Unity3d使用json能够借助LitJson

下载LitJson,复制到Unity3d工作文件夹下

于是能够在代码中实现了

以下发送请求到server并解析


System.Collections.Hashtable headers = new System.Collections.Hashtable ();
		
		headers.Add ("Content-Type","application/x-www-form-urlencoded");
	
		string data = "token="+User.token;
		byte[] bs = System.Text.UTF8Encoding.UTF8.GetBytes (data);
		WWW www = new WWW ("http://127.0.0.1:8080/userver/st",bs,headers);

		yield return www;

		if(www.error!=null){

			m_info=www.error;

			yield return null;

		}

		JsonData listJson = JsonMapper.ToObject (www.text);
		//server返回map数组
 		Debug.Log (listJson[0][0]);
		//json对象的值能够通过下标或者key获取
		Debug.Log (listJson[0]["r"]);





相关文章:

  • 2021-10-23
  • 2022-12-23
  • 2021-10-03
  • 2022-12-23
  • 2022-12-23
  • 2021-09-20
猜你喜欢
  • 2022-02-14
  • 2021-06-10
  • 2022-12-23
  • 2021-07-12
  • 2022-01-20
  • 2021-06-27
相关资源
相似解决方案