JSON解析
JsonData jsonData = JsonMapper.ToObject(File.ReadAllText("json.txt"));
JsonData notes = jsonData["employees"];//获取到数组
for (int i = 0; i < notes.Count; i++) {
    Console.WriteLine(notes[i]["firstName"]);//获取到对象
}

Skill[] skillArray = JsonMapper.ToObject<Skill[]>(File.ReadAllText("文件名"));

Skill类里面的属性要与json里面对应,模型对应

注意,c#没有内置的json解析器,需要下载,这里用的是LitJSON,下载dll文件,引入即可


也可以使用UnityEngine内置的JsonUtility类来解析json数据。

[Serializable]
public class Data
{
    public int status;
    public string msg;
    public string WaterMark;
}

Data data = null;
try
{
    data = JsonUtility.FromJson<Data>(json);
}
catch (Exception e)
{
    yield break;
}

首页 我的博客
粤ICP备17103704号