如何使用JSON.NET反序列化JSON来解释? [英] How to deserialize JSON to Dictionary using JSON.NET?

查看:91
本文介绍了如何使用JSON.NET反序列化JSON来解释?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从 http://www.imdbapi.com 查询数据,并想利用解析结果 Json.net 库。可能有人请告诉我,我该怎么使用这个库的查询响应成地图<转换,字符串,字符串>



有了这个代码,我能够得到所有钥匙,却怎么也查询中值呢?



  JObject的obj = JObject.Parse(响应); 
&IList的LT;字符串>道具= obj.Properties()选择(P => p.Name)。.ToList();


解决方案

尝试的 JSON.NET



只需使用这样的:

 词典<字符串,字符串> movieValues = 
JsonConvert.DeserializeObject<&字典LT;字符串,字符串>>(responseFromImdbApi);



刚刚得到的值是这样的:

  movieValues [标题] 
movieValues [释放]
movieValues [流派]


I am querying data from http://www.imdbapi.com and would like to parse the result using Json.net library. Could someone please tell me how I can use this library to convert the query response into a Map<string, string>.

With this code I'm able to get all keys, but how can query the values then?

   JObject obj = JObject.Parse(response);
   IList<string> props = obj.Properties().Select(p => p.Name).ToList();

解决方案

Try JSON.NET

Just use this:

Dictionary<string, string> movieValues = 
     JsonConvert.DeserializeObject<Dictionary<string, string>>(responseFromImdbApi);

Just get the values like this:

movieValues["title"] 
movieValues["released"]
movieValues["genre"]

这篇关于如何使用JSON.NET反序列化JSON来解释?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆