Newtonsoft JSON反序列化 [英] Newtonsoft JSON Deserialize
本文介绍了Newtonsoft JSON反序列化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的JSON如下:
{"t":"1339886","a":true,"data":[],"Type":[['Ants','Biz','Tro']]}
我发现Newtonsoft JSON.NET反序列化库,用于C#。我试图用它如下:
I found the Newtonsoft JSON.NET deserialize library for C#. I tried to use it as follow:
object JsonDe = JsonConvert.DeserializeObject(Json);
我如何可以访问到 JsonDe
对象来获取所有的类型的数据?我用一个循环尝试过,但它不工作,因为对象没有一个枚举。
How can I access to the JsonDe
object to get all the "Type" Data? I tried it with a loop but it is not working because the object does not have an enumerator.
推荐答案
您可以实现保存你的字段的JSON类
You can implement a class that holds the fields you have in your JSON
class MyData
{
public string t;
public bool a;
public object[] data;
public string[][] type;
}
然后用DeserializeObject通用版:
and then use the generic version of DeserializeObject:
MyData tmp = JsonConvert.DeserializeObject<MyData>(json);
foreach (string typeStr in tmp.type[0])
{
// Do something with typeStr
}
文档: 序列化和反序列化JSON
这篇关于Newtonsoft JSON反序列化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文