我一直在使用NewtonSoft JSON 转换 http://james.newtonking.com/json用于解析 JSON 字符串并将其转换为 C# 对象的库。但现在我遇到了一个非常尴尬的 JSON 字符串,我无法将其转换为 C# 对象,因为我无法用这个 JSON 字符串创建 C# 类。
这是 JSON 字符串
{
"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"
}
}
解析此 JSON 字符串所需的 C# 类应如下所示:
public class 1 {
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; }
}
public class 2 {
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; }
}
但它不可能是真正的 C# 类,因为我们知道类名不能以数字开头。
如果有人能建议如何解析这种类型的 json 字符串,那就太好了。