我的 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 反序列化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!
读取 XML 时忽略空格Ignore whitespace while reading XML(读取 XML 时忽略空格)
带有检查空元素的 XML 到 LINQXML to LINQ with Checking Null Elements(带有检查空元素的 XML 到 LINQ)
在 C# 中读取带有未闭合标签的 XMLReading XML with unclosed tags in C#(在 C# 中读取带有未闭合标签的 XML)
在 C# 中使用 Html 敏捷性解析表格、单元格Parsing tables, cells with Html agility in C#(在 C# 中使用 Html 敏捷性解析表格、单元格)
使用 LINQ 从 xml 中删除元素delete element from xml using LINQ(使用 LINQ 从 xml 中删除元素)
解析格式错误的 XMLParse malformed XML(解析格式错误的 XML)