json解析
Posted Fei非非
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了json解析相关的知识,希望对你有一定的参考价值。
using UnityEngine;
using System.Collections;
using LitJson;
public class jsonjx : MonoBehaviour
{
// Use this for initialization
void Start () {
StartCoroutine(downJson());
}
IEnumerator downJson()
{
string url = "http://192.168.0.116/index.php?m=App&c=Api&a=room&ajax=json";
WWW www = new WWW(url);
yield return www;
Debug.Log(www.text);
JsonJx(www.text);
}
//解析json
void JsonJx(string str)
{
JsonData jd = JsonMapper.ToObject(str);
for (int i = 0; i < jd.Count; i++)
{
string id = jd[i]["sid"].ToString();
Debug.Log("jd[i][sid]++++" + id);
}
}
}
json文档放在本地的服务器上即可
[{"sid":"15","name":"\u82f9\u679c","name_en":"apple","img":"\/data\/upload\/app\/word\/15\/572f07fbd8b50.jpg","android_url":"\/data\/upload\/app\/model\/\/B.assetbundle","ios_url":"\/data\/upload\/app\/model\/\/B.assetbundle","time":"1466751740"},{"sid":"14","name":"\u7334\u5b50","name_en":"monkey","img":"\/data\/upload\/app\/model\/14\/574971815909d.jpg","android_url":"\/data\/upload\/app\/model\/14\/B.assetbundle","ios_url":"\/data\/upload\/app\/model\/14\/B.assetbundle","time":"1466660131"},{"sid":"13","name":"F\u573a\u666f","name_en":"f_scenes","img":"\/data\/upload\/scene\/572f07fbd8b50.jpg","android_url":"http:\/\/192.168.0.116\/data\/upload\/scene\/F.assetbundle","ios_url":"http:\/\/192.168.0.116\/data\/upload\/scene\/F.assetbundle","time":"1466418165"},{"sid":"12","name":"E\u573a\u666f","name_en":"e_scenes","img":"http:\/\/192.168.0.116\/data\/upload\/scene\/E.png","android_url":"http:\/\/192.168.0.116\/data\/upload\/scene\/E.assetbundle","ios_url":"http:\/\/192.168.0.116\/data\/upload\/scene\/E.assetbundle","time":"1466404665"},{"sid":"11","name":"D\u573a\u666f","name_en":"d_scenes","img":"http:\/\/192.168.0.116\/data\/upload\/scene\/D.png","android_url":"http:\/\/192.168.0.116\/data\/upload\/scene\/D.assetbundle","ios_url":"http:\/\/192.168.0.116\/data\/upload\/scene\/D.assetbundle","time":"1466404604"},{"sid":"10","name":"C\u573a\u666f","name_en":"c_scenes","img":"http:\/\/192.168.0.116\/data\/upload\/scene\/C.png","android_url":"http:\/\/192.168.0.116\/data\/upload\/scene\/C.assetbundle","ios_url":"http:\/\/192.168.0.116\/data\/upload\/scene\/C.assetbundle","time":"1466417670"}]
以上是关于json解析的主要内容,如果未能解决你的问题,请参考以下文章
使用 json rereiver php mysql 在片段中填充列表视图
ios - Heroku 和 MongoDb 上的自定义解析服务器错误 3080:JSON 文本没有以数组或对象开头,并且允许未设置片段的选项