这几天做自己的培训班的毕业项目,涉及到Json的读取与写入,本来想用LitJson的,后来发现5.3以后的版本有自带的实现,而且很方便,配合System.IO就可以方便的实现,网上这方面资料也不少,但这里给出更具体的实现,例如Json文件中不只有一个对象,涉及多对象的时候怎么办,适合初学者看看。
1.首先看Json文件
//////////////// testJson.json ////////////////////
{
"inforList": [{"sceneName": "scene0",
"version": 1.0,
"score": 250
}, {
"sceneName": "scene1",
"version": 1.0,
"score": 150
}, {
"sceneName": "scene2",
"version": 1.0,
"score": 400
}]
}
这个文件位置是在 Asset/Resources/ 文件夹下面的
////////////////////////////////////
2. 对应的Json数据类
//////////////////////////// PlayerInfo.cs //////////
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
[System.Serializable]
public c