[英]Deserialize json in C#
I am trying to deserialize this json using C#: 我正在尝试使用C#反序列化此json:
{"query":
{"count":10,"created":"2011-06-18T19:15:24Z","lang":"en-US","results":
{"Result":[{"id":"21373494","Title":"Sushi Bistro","Address":"455 Balboa St","Rating":
{"AverageRating":"5"}
}
{"Result":[{"id":"21373495","Title":"Sushi Bistro","Address":"4565 Balboa St","Rating":
{"AverageRating":"1"}
}
}
}
I tried Newton json.NET, then used JSONHelper class, but it didn't work. 我尝试了牛顿json.NET,然后使用了JSONHelper类,但是没有用。 Could someone provide a short sample how to deserialize to the object and loop through 'Result' in C#?
有人可以提供一个简短的示例,介绍如何反序列化对象并在C#中遍历“结果”吗?
UPDATE: sorry for invalid json, ouput is crazy big, so I tried to copy just a small part. 更新:抱歉,无效的json,输出太疯狂了,所以我尝试复制一小部分。 However you can see a pattern of Result set in here.
但是,您可以在此处看到结果集的模式。
Json provided above is invalid, try to fix json first and after this i guess your code will work. 上面提供的Json无效,请尝试首先修复json,然后我猜您的代码将工作。
You can use jsonlint service to validate json. 您可以使用jsonlint服务来验证json。
Example of deserializing json from string using newton json dll: 使用牛顿json dll从字符串反序列化json的示例:
var json = "..";
string output = JsonConvert.DeserializeObject<MyClass>(json);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.