标签:unity3d
Unity3d使用json可以借助LitJson
下载LitJson,拷贝到Unity3d工作目录下
于是可以在代码中实现了
下面发送请求到服务器并解析
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); //服务器返回map数组 Debug.Log (listJson[0][0]); //json对象的值可以通过下标或者key获取 Debug.Log (listJson[0]["r"]);
</pre><pre code_snippet_id="503706" snippet_file_name="blog_20141031_3_1427346" name="code" class="csharp">下面是服务器数据
</pre><pre code_snippet_id="503706" snippet_file_name="blog_20141031_5_2276003" name="code" class="java"> Map<String,Object> map=new HashMap<String,Object>(); map.put("r","1212121212d12"); map.put("e","1212121212a12"); map.put("a","1212121212d12"); map.put("f","1212121212c12"); map.put("d","12121212121g2"); map.put("s","sdfdsfds");
标签:unity3d
原文地址:http://blog.csdn.net/angelmymei/article/details/40660599