Unity3d uses json to communicate with the java Server
Unity3d json can be used with LitJson
Download LitJson and copy it to the Unity3d working directory.
So we can implement
Send the following request to the server and parse it
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); // The server returns the map array Debug. log (listJson [0] [0]); // The value of the json object can be obtained through subscript or key Debug. log (listJson [0] ["r"]);
Below are the server data
Map
map=new HashMap
();map.put("r","1212121212d12");map.put("e","1212121212a12");map.put("a","1212121212d12");map.put("f","1212121212c12");map.put("d","12121212121g2");map.put("s","sdfdsfds");