简体   繁体   English

在ASP.NET中解析JSON

[英]Parsing JSON in ASP.NET

I have the following JSOn I need to parse: 我需要解析以下JSOn:

{"items":[{"dict":"es","words":[{"word":"car","id":"3487"},{"word":"dog","id":"443"},{"word":"plane","id":"1171"}]},{"dict":"fr","words":[{"word":"house","id":"134"}]}]} 

Using JavaScriptSerializer, how could I iterate first through each dict and then retrieve the id of each word? 使用JavaScriptSerializer,如何首先遍历每个字典,然后检索每个单词的ID?

make anonymouse type, acording your json, for example: 根据您的json设置匿名类型,例如:

var result = new[] {new {action = "", value = false}}; // put your item structure here
var list   = JsonConvert.DeserializeObject(myJson, result.GetType());

then you might want to itterate through. 那么您可能想要通过。 For example: 例如:

foreach (dynamic val in  ((dynamic) list)) { ...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM