纳金网
标题:
json解析(纯代码+注释)
[打印本页]
作者:
烟雨
时间:
2015-8-29 02:05
标题:
json解析(纯代码+注释)
//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
["id"].ToString();
print(id);
}
}
}
欢迎光临 纳金网 (http://www.narkii.com/club/)
Powered by Discuz! X2.5