1.插件
2.在Assets/Json中新建一个txt文件(另存为UTF-8格式)
内容:
{
"name":"张三",
"skillList":
[
{
"id":101,
"name":"无影脚"
},
{
"id":102,
"name":"罗汉拳"
}
]
}
3.新建Skill类
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
/*
*文件描述:
*创始人:
*创建时间:
*修改时间:
*版本:1.0
*/
public class Skill
{
public int id { get; set; }
public string name { get; set; }
public override string ToString()
{
return string.Format("id:{0},name:{1}", id, name);
}
}
4.新建Role 类
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
/*
*文件描述:
*创始人:
*创建时间:
*修改时间:
*版本:1.0
*/
public class Role {
public string name { get; set; }
public List<Skill> skillList { get; set; }
public override string ToString()
{
return string.Format("id:{0},list:{1}", name, skillList);
}
}
5.新建Test类
public class Test : MonoBehaviour
{
void Start()
{
Get4();
}
void Get4()
{
string path = Application.dataPath + "/Json/Role.txt";
Role roel = JsonMapper.ToObject<Role>(File.ReadAllText(path));
print(roel.name);
foreach (Skill item in roel.skillList)
{
print(item);
}
}
}