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");
Unity3d使用json与javaserver通信的更多相关文章
- Unity3d之json解析研究
Unity3d之json解析研究 json是好东西啊!JSON(JavaScript Object Notation) 是一种轻量级的数据交换格式 JSON简单易用,我要好好研究一下 ...
- Unity3D游戏,TCP,WEBCOSKT,HTTP通信架构 weaving-socket
weaving-socket 详细介绍 项目简介 2017-8-8:新发布功能 增加U3D游戏客户的通讯项目支持,并提供示例内容. 2017-5-5: 新发布 weaving-socket 架构的.n ...
- [PHP 作为iOS后台Json格式HTTP通信及文件上传的实现]
1.数据库连接 configmysql.php <?php $q = mysql_connect("localhost:8889","root",&quo ...
- Unity3D 通过JSON查询天气
一.天气查询API 获取天气信息,首先要找到提供天气数据的接口,我使用的是高德地图免费为我们提供的,网址为 https://lbs.amap.com/api/webservice/guide/api/ ...
- json方式封装接口通信
编写response类: <?php class response{ /** * 按json方式输出通信数据 * @param integer $code 状态码 * @param string ...
- 04 json,xml混合封装通信
<?php class Response_json_xml{ public static function show($code,$message="",$data=arra ...
- NetworkComms V3 使用Json序列化器进行网络通信
刚才在网上闲逛,偶然看到一篇文章 C#(服务器)与Java(客户端)通过Socket传递对象 网址是:http://www.cnblogs.com/iyangyuan/archive/2012/12/ ...
- php和js如何通过json互相传递数据
当我们在结合php和javascript实现某些功能时,经常会用到json.json是js的一种数据格式,可以直接被js解析.而php无法直接读取json数据,但是php提供了json_decode函 ...
- php生成json或者xml数据
, ,'数据返回成功',$arr);echo $xml;?>
随机推荐
- navicat for mysql 快捷键
1.ctrl+q 打开查询窗口2.ctrl+/ 注释sql语句3.ctrl+shift +/ 解除注释4.ctrl+r 运行查询窗口的s ...
- Python开发基础-Day33 IO模型
IO模型分类 五种IO Model blocking IO 阻塞IO nonblocking IO 非阻塞IO IO multiplexing IO多路复用 signal driven IO 信号驱动 ...
- Python并发编程-进程
由于GIL(全局解释锁)的问题,多线程并不能充分利用多核处理器,如果是一个CPU计算型的任务,应该使用多进程模块 multiprocessing .它的工作方式与线程库完全不同,但是两种库的语法和接口 ...
- 使用matplotlib绘图(二)之柱状图
# 使用matplotlib绘制柱状图 import numpy as np import matplotlib.pyplot as plt # 设置全局字体,以支持中文 plt.rcParams[' ...
- 【BZOJ 2006】2006: [NOI2010]超级钢琴(RMQ+优先队列)
2006: [NOI2010]超级钢琴 Time Limit: 20 Sec Memory Limit: 552 MBSubmit: 2792 Solved: 1388 Description 小 ...
- luoguP4206 [NOI2005]聪聪与可可 期望概率DP
首先,分析一下这个猫和鼠 猫每局都可以追老鼠一步或者两步,但是除了最后的一步,肯定走两步快些.... 既然猫走的步数总是比老鼠多,那么它们的距离在逐渐缩小(如果这题只能走一步反而不能做了...) 猫不 ...
- Test20171009 考试总结 NOIP模拟赛
题目难度合适,区分度适中,但是本人水平不佳,没有拿到满意的分数. T1(matrix) 一种比较容易想到的想法是枚举起点求出最长全1串做预处理,这是O(n^2)的. 接着枚举列起点,列终点,通过后缀和 ...
- bzoj 4874: 筐子放球
4874: 筐子放球 Time Limit: 10 Sec Memory Limit: 256 MB Description 小N最近在研究NP完全问题,小O看小N研究得热火朝天,便给他出了一道这样 ...
- HBase EndPoint加载失败
概述 参考博客(http://blog.csdn.net/carl810224/article/details/52224441)编写EndPoint协处理器,编写完成后使用Maven打包(使用ass ...
- apose 根据excel 导出模版
string file = Server.MapPath("~/Excel/ZWxxtj.xls"); DataSet ds = new DataSet(); ...