如何从json数据下面获取combined_rate值
{
"rate": {
"zip": "10005",
"state": "NY",
"state_rate": "0.04",
"county": "NEW YORK",
"county_rate": "0.0",
"city": "NEW YORK CITY",
"city_rate": "0.045",
"combined_district_rate": "0.00375",
"combined_rate": "0.08875"
}
}
请提前帮助此致谢
答案 0 :(得分:0)
您可以定义自定义类:
internal class Data
{
public Rate rate;
}
internal class Rate
{
public float combined_rate;
}
将此字符串反序列化为object:
var s = new JavaScriptSerializer();
var o = s.Deserialize<Data>(json);
var value = o.rate.combined_rate;
此外,您可以从字符串中提取其他值,只需将新字段添加到Data
类。