Unity3d使用json与javaserver通信

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"]);
</pre><pre code_snippet_id="503706" snippet_file_name="blog_20141031_3_1427346" name="code" class="csharp">以下是server数据
</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");
时间: 2024-08-01 22:57:18

Unity3d使用json与javaserver通信的相关文章

Unity3d使用json与java服务器通信

Unity3d使用json可以借助LitJson 下载LitJson,拷贝到Unity3d工作目录下 于是可以在代码中实现了 下面发送请求到服务器并解析 System.Collections.Hashtable headers = new System.Collections.Hashtable (); headers.Add ("Content-Type","application/x-www-form-urlencoded"); string data = &q

Unity3d之json解析研究

Unity3d之json解析研究 json是好东西啊!JSON(JavaScript Object Notation) 是一种轻量级的数据交换格式      JSON简单易用,我要好好研究一下,和大家共享一下.      想了解更详细的数据可以参考一下百科:http://baike.baidu.com/view/136475.htm      好了,我们步入正题:unity3d使用json      我写了4个方法:ReadJson(),ReadJsonFromTXT();WriteJsonAn

[PHP 作为iOS后台Json格式HTTP通信及文件上传的实现]

1.数据库连接 configmysql.php <?php $q = mysql_connect("localhost:8889","root","root"); if(!$q) { die('Could not connect: ' . mysql_error()); } mysql_query("set names utf8"); //以utf8读取数据 //mysql_select_db("myDB&qu

Unity3d Atlas json格式化

修改texturepacker生成的json串之后,对其进行格式化,相关代码: public static string JsonTree(string json) { int level = 0; var jsonArr = json.ToArray(); string jsonTree = string.Empty; for (int i = 0; i < json.Length; i++) { char c = jsonArr[i]; if (level > 0 && '

unity3D和串口之间的通信,接收下位机数据和发送指令

using UnityEngine;using System.Collections;using System.IO.Ports;using System;using System.Collections.Generic;using System.Threading; public class PortControl : MonoBehaviour { public GUIText gui; public string portName = "COM2"; public int bau

json方式封装接口通信

编写response类: <?php class response{ /** * 按json方式输出通信数据 * @param integer $code 状态码 * @param string $message 提示信息 * @param array $data 提示信息 * return string */ public static function json($code,$message = '',$data = array()){ if(!is_numeric($code)){ ret

U3D 网络库实现通信 基于Warensoft Unity3d

Warensoft Unity3d Communication Lib this is a high performance communication library for Unity3d,including some easy-to-use httpclasses,andsocket classes. And especially,it brings a totally new method to access to MS SQL SERVER2005+via http protocol.

04 json,xml混合封装通信

<?php class Response_json_xml{ public static function show($code,$message="",$data=array(),$type){ if(is_null($code)){ return ''; } $data=array( 'code'=>$code, 'message'=>$message, 'data'=>$data ); if($type=="json"){ self::

xml和json格式输出

<?php class Response{ const JSON ='json'; /* * 按综合方式输出通信数据 * @param integer $code 状态码 * @param string $message 提示信息 * @param array $data 数据 * @param string $type 数据类型 * return string */ public static function show($code,$message='',$data=array(),$typ