我的 JSON 如下:
My JSON is as follows:
{"t":"1339886","a":true,"data":[],"Type":[['Ants','Biz','Tro']]}
我找到了用于 C# 的 Newtonsoft JSON.NET 反序列化库.我尝试按如下方式使用它:
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 反序列化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!