参照链接:https://blog.csdn.net/yy763496668/article/details/77875195
我的数据如下:
{
"Know": [
"A",
"1" ,
"" ,
],
"Projects": [
{
"ProjectName": "1",
"Properties": {
"Info": "ab",
"tech": "他",
"type": "100%",
"time": "2019-09-04"
},
"Data": {
"req":"20",
"List": [
{
"time": "2019-09-03",
"item": "10"
},
{
"time": "2019-09-04",
"item": "10"
}
],
"const": 100,
"fer": "正常",
"Harvest": "1000"
}
}, {
"ProjectName": "2",
"Properties": {
"Info": "ab",
"tech": "你",
"type": "80%",
"time": "2019-09-04"
},
"Data": {
"req":"30",
"List": [
{
"time": "2019-09-03",
"item": "20"
},
{
"time": "2019-09-04",
"item": "10"
}
],
"const": 100,
"fer": "50%",
"Harvest": "800"
}
}
]
}
定义相应的数据结构比较麻烦。
在使用JsonUtility.ToJson时,发现Projects对应的对象没有转换成功。
在类上添加序列化头[System.Serializable]就成功了。
以上是参考开头链接的文章。
最重要的是需要注意:
1、可被序列化的对象类,要用使用[System.Serializable]特性。
2、只能序列化类中的公有成员变量,属性不行!