Use the dictionary
The following is an example of handling this situation with dictionary:
For the JSON string in the problem:
public class Item { public string fajr { get; set; } public string sunrise { get; set; } public string zuhr { get; set; } public string asr { get; set; } public string maghrib { get; set; } public string isha { get; set; } } // 将JSON字符串反序列化为字典 var dict = JsonConvert.DeserializeObject<Dictionary<string, Item>>(json);
You can use the string key ("1" and "2") to access the data in the dictionary, for example:
{ "1": { "fajr": "04:15", "sunrise": "05:42", "zuhr": "12:30", "asr": "15:53", "maghrib": "19:18", "isha": "20:40" }, "2": { "fajr": "04:15", "sunrise": "05:42", "zuhr": "12:30", "asr": "15:53", "maghrib": "19:18", "isha": "20:41" } }
The above is the detailed content of How to Deserialize JSON with Illegal C# Identifiers?. For more information, please follow other related articles on the PHP Chinese website!