如何在JSON中解码这些数据?

时间:2013-09-30 17:23:47

标签: c# json serialization

我在尝试使用JSON解码此数据时感到很茫然。

这是从URL返回的数据。它可以缓存或其他东西,它每年改变一次:)

  

[{ “的service_type”: “1”, “价格”: “0,62”, “money_added”: “0,31”, “值”: “70068”, “类型”: “TTL.X50” },{ “的service_type”: “2”, “价格”: “1,23”, “money_added”: “0.61”, “值”: “71068”, “类型”: “TTL.X100”}, { “的service_type”: “3”, “价格”: “2,46”, “money_added”: “1,22”, “值”: “72068”, “类型”: “TTL.X200”},{” SERVICE_TYPE “:” 4" , “价格”: “3,69”, “money_added”: “1,80”, “值”: “73068”, “类型”: “TTL.X300”},{ “的service_type” : “5”, “价格”: “4,92”, “money_added”: “2,45”, “值”: “74068”, “类型”: “TTL.X400”},{ “的service_type”:” 6" , “价格”: “6,15”, “money_added”: “3,05”, “值”: “75068”, “类型”: “TTL.X500”},{ “的service_type”: “7” , “价格”: “7.38”, “money_added”: “3,65”, “值”: “76068”, “类型”: “TTL.X600”},{ “的service_type”: “8”,”价 “:” 11,07" , “money_added”: “5,50”, “值”: “79068”, “类型”: “TTL.X900”},{ “的service_type”: “11”, “价格” : “12,30”, “money_added”: “6,10”, “值”: “91058”, “类型”: “TTL.X10”},{ “的service_type”: “12”, “价格”:” 20,91" , “money_added”: “10,40”, “值”: “91758”, “类型”: “TTL.X170”},{ “的service_type”: “9”, “价格”:“23, 37" , “money_added”: “11,60”, “值”: “91958”, “类型”:” TTL.X190 “},{” 的service_type “:” 13" , “价格”: “24,60”, “money_added”: “12,20”, “值”: “92058”, “类型”:“TTL。 X20 “},{” 的service_type “:” 10" , “价格”: “30,75”, “money_added”: “15,80”, “值”: “92578”, “类型”: “TTL.X250” }]

如何从功能中轻松访问?我尝试使用“newtonsoft”反序列化JSON但是我的确失败了。

非常感谢任何帮助!

1 个答案:

答案 0 :(得分:1)

var services = JsonConvert.DeserializeObject<List<Service>>(yourjson);

public class Service
{
    public string service_type { get; set; }
    public string price { get; set; }
    public string money_added { get; set; }
    public string value { get; set; }
    public string type { get; set; }
}