Unity Json反序列化嵌套数据 [英] Unity Json De/serializing nested data
问题描述
请帮助我!我正在尝试从json文件中读取大量数据,并且数据的大部分是列表列表!我不知道如何反序列化它!
因此我找到了本指南,并像他一样使用JsonFX
Visual Studio 2015示例:
please help me! I'm trying to read a big chunk of data from a json file and most part of the data is a list of list! I dont know how to deserialize it!
So I found this guide, and did as him using the JsonFX http://www.raybarrera.com/2014/05/18/json-deserialization-using-unity-and-jsonfx/
it helped me deserialize all the other information I need except the list of list.
The following is an example of how the json file may look like, keep in mind I simplified it ten folds, cuz this is a huge dataset!
{
"name": "Croissant",
"price": 60,
"foo": [{
"poo": [1, 2]
},
{
"poo": [3, 4]
}
],
"importantdata": [
[
0,
1,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
],
[
1,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
]
]
}
So how can I make this into an object and reach the data I need like this myObject.importantdata[n]
?
If more information is needed I'm happy to share, sorry Im new here!
You can generate the POCO class using your sample data, try http://json2csharp.com/, which is an online tool. Visual Studio 2015 onward and VS code also has a similar menu item/command to accomplish this.
- Paste your json string there
- you will get all the POCO classes you need.
The auto-generated result for your case is:
public class Foo
{
public List<int> poo { get; set; }
}
public class RootObject
{
public string name { get; set; }
public int price { get; set; }
public List<Foo> foo { get; set; }
public List<List<int>> importantdata { get; set; }
}
VS Code example:
Visual Studio 2015 example:
这篇关于Unity Json反序列化嵌套数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!