Unity3D培训
美国上市Unity3D培训机构

400-111-8989

热门课程

Unity3D脚本:Unity3D使用LitJson解析服务器上的JSON

  • 发布:Unity3D培训
  • 来源:Unity3D教程
  • 时间:2016-01-25 17:18

请保证工程里面已经加入了LitJson.dll服务器上JSON的内容。

[{"people":[

{"name":"fff","pass":"123456","age":"1", "info":{"sex":"man"}},

{"name":"god","pass":"123456","age":"1","info":{"sex":"woman"}},

{"name":"kwok","pass":"123456","age":"1","info":{"sex":"man"}},

{"name":"tom","pass":"123456","age":"1","info":{"sex":"woman"}}

]}

]

LoadControl_c代码:

using UnityEngine;

using System.Collections;

using LitJson;

public class LoadControl_c:MonoBehaviour

{

private GameObject plane;

public string url = "http://127.0.0.1/test2.txt";

// Use this for initialization

void Start()

{

StartCoroutine(LoadTextFromUrl());

//StartCoroutine(DoSomething());

//Book book = new Book("Android dep");

//InvokeRepeating("LaunchProjectile", 1, 5);

}

IEnumerator DoSomething()

{

yield return new WaitForSeconds(3);

}

IEnumerator LoadTextFromUrl()

{

if (url.Length > 0)

{

WWW www = new WWW(url);

yield return www;

//string data = www.data.ToString().Substring(1);

string data = www.text.ToString().Substring(1);

// 下面是关键

print(data);

LitJson.JsonData jarr = LitJson.JsonMapper.ToObject(www.text);

if(jarr.IsArray)

{

for (int i = 0; i < jarr.Count; i++)

{

Debug.Log(jarr[i]["people"]);

JsonData jd = jarr[i]["people"];

for(int j = 0; j < jd.Count; j++)

{

Debug.Log(jd[j]["name"]);

}

}

}

}

}

}

预约申请免费试听课

上一篇:Unity3D脚本:Unity3D 车身与玻璃材质
下一篇:Unity3D脚本:限定游戏的时间脚本
Unity|超级兔子

Unity|超级兔子

Unity超级角色控制器物理API分析与功能实现

Unity超级角色控制器物理API分析与功能实现

教程:让Unity中物理效果更加逼真

教程:让Unity中物理效果更加逼真

Unity3D 软件下载

Unity3D 软件下载

选择城市和中心
贵州省

广西省

海南省