我有以下json:
{
"578080":{
"success":true,
"data":{
"price_overview":{
"currency":"USD",
"initial":1799,
"final":1799,
"discount_percent":0
}
}
}
}
我要搜索“初始”。
我如何使用 Json.Net 或C#中的任何其他有效方法来做到这一点?
注意:我没有尝试任何操作,因为我不确定从哪里开始
答案 0 :(得分:0)
因为这是Dictionary<string,object>
,所以您可以遵循此Deserialize a Dictionary
public class PriceOverview
{
public string currency { get; set; }
public int initial { get; set; }
public int final { get; set; }
public int discount_percent { get; set; }
}
public class Data
{
public PriceOverview price_overview { get; set; }
}
public class RootObject
{
public bool success { get; set; }
public Data data { get; set; }
}
var results = JsonConvert.DeserializeObject<Dictionary<string, RootObject>>(json);
foreach (var result in results)
{
Console.WriteLine(result.Key);
Console.WriteLine(result.Value.data.price_overview.currency);
Console.WriteLine(result.Value.data.price_overview.initial);
Console.WriteLine(result.Value.data.price_overview.final);
Console.WriteLine(result.Value.data.price_overview.discount_percent);
}
输出
578080
USD
1799
1799
0