- 最后登录
- 2019-12-25
- 注册时间
- 2012-8-24
- 阅读权限
- 90
- 积分
- 71088
- 纳金币
- 52336
- 精华
- 343
|
//json
{
"Home":[
{"id":1,"name":"爱家1"},
{"id":11,"name":"爱家11"},
{"id":111,"name":"爱家111"}
]
}
//解析json
using UnityEngine;
using System.Collections;
using LitJson;
public class ReadJSON : MonoBehaviour {
//获取文件(直接拖拽)
public TextAsset txt;
void Start () {
ReadJson();
}
//解析json
public void ReadJson()
{
//获取json数据
JsonData json = JsonMapper.ToObject(txt.ToString());
//获取需要解析的节点列表
JsonData js = json["Home"];
//遍历
for (int i = 0; i < js.Count; i++)
{
//存储值
string id = js[i]["id"].ToString();
print(id);
}
}
}
|
|