C#如何检索JSON数据到一个数组 [英] c# How to retrieve Json data into an array

查看:280
本文介绍了C#如何检索JSON数据到一个数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我发现,可以解析JSON数据不同的库,但我没有找到如何将数据进入一个C#数组或列表中的任何文件。

我得到这个JSON数据:

{001:{姓名:约翰,手机:暴民 - 98837374,暴民 - 98363627]},
 002:{名:汤姆,手机:暴民 - 49858857]}}

任何人有线索? :)

修改

有用的细节由OP张贴评论重新张贴由AnthonyWJones问题编辑

使用JSON.NET我的code:

  StringBuilder的SB =新的StringBuilder();
清单<串GT;实体=(列表<串GT;)JsonConvert.DeserializeObject(responseFromServer的typeof(名单<串GT;));
的foreach(在实体字符串项){
  sb.Append(项目);
}

但我总是得到一个错误,当我调试:


  

    

警告1参考键入它在C:\\程序文件>> \\ Microsoft.NET \\ SDK \\ CompactFramework \\ v3.5版本\\ Windows CE的\\ mscorlib.dll中'定义'System.DateTimeOffset的主张,但它不能>>找到C:\\股利\\ Json的点网\\ BIN \\ Newtonsoft.Json.dll


  

解决方案

有一个看看这个:的解析JSON使用Json.net

下面是序列化和反序列化数组一些Json.NET特定文档:<一href=\"http://james.newtonking.com/projects/json/help/index.html?topic=html/SerializingCollections.htm\"相对=nofollow>序列化集合与Json.NET

I have found different libraries that can parse Json data, but i did not find any documentation on how to get the data into an C# array or list.

I got this Json data:

{"001":{"Name":"John", "Phone":["Mob - 98837374","Mob - 98363627"]}, "002":{"Name":"Tom", "Phone":["Mob - 49858857"]}}

Anybody got a clue? :)

Edit:

Useful details posted by OP as comments re-posted as question edit by AnthonyWJones

My code using JSON.NET:

StringBuilder sb = new StringBuilder();
List<string> entities = (List<string>)JsonConvert.DeserializeObject(responseFromServer, typeof(List<string>));
foreach (string items in entities) {
  sb.Append(items);
}

But i always get an error when i debug:

Warning 1 Reference to type 'System.DateTimeOffset' claims it is defined in 'c:\Program >> Files\Microsoft.NET\SDK\CompactFramework\v3.5\WindowsCE\mscorlib.dll', but it could not >> be found c:\Div\Json dot net\Bin\Newtonsoft.Json.dll"

解决方案

Have a look at this: Parsing JSON using Json.net

Here is some Json.NET specific documentation for serializing and deserializing arrays: Serializing Collections with Json.NET

这篇关于C#如何检索JSON数据到一个数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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