位置: 编程技术 - 正文

unity请求json数据并解析(unity jsonobject)

编辑:rootadmin

推荐整理分享unity请求json数据并解析(unity jsonobject),希望有所帮助,仅作参考,欢迎阅读内容。

文章相关热门搜索词:unity jsonobject,unity post请求,unity中json有几种结构,unity jsonutility,unity中json有几种结构,unity jsonobject,unity解析json数据,unity json,内容如对您有帮助,希望把文章链接给更多的朋友!

unity3d在跟.net进行http通信的时候,最常见的就是表单数据的提交请求了,但服务器端会返回一坨json数据,这就要求我们在unity中进行json数据的处理了,一般unity中处理json个数数据用的最多的就是LitJSON(它是.net平台下处理SON数据库的类库)。下面我就贴出源码,仅供学习参考!

unity请求json数据并解析(unity jsonobject)

关于LitJSON的安装和使用,请参考: view plaincopyprint?using UnityEngine; using System.Collections; using LitJson; public class GetPhotoList : MonoBehaviour { // Use this for initialization void Start () { StartCoroutine(GetPhotos()); } // Update is called once per frame IEnumerator GetPhotos(){ WWWForm form = new WWWForm(); form.AddField("id",""); WWW w = new WWW(" while (!w.isDone){yield return new WaitForEndOfFrame();} if (w.error != null){Debug.LogError(w.error);} Debug.Log(w.text); JsonData jd = JsonMapper.ToObject(w.text); for (int i = 0; i < jd.Count; i&#;&#;) { Debug.Log("id=" &#; jd[i]["id"]); Debug.Log("name=" &#; jd[i]["name"]); } } } Server:

[plain] view plaincopyprint?using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Runtime.Serialization.Json; using System.ServiceModel; using System.ServiceModel.Web; using System.IO; namespace UpdatePhoto { /// <summary> /// GetPhotoList 的摘要说明 /// </summary> public class GetPhotoList : IHttpHandler { public void ProcessRequest(HttpContext context) { context.Response.ContentType = "text/plain"; string id = context.Request.Form["id"]; string path = context.Request.PhysicalApplicationPath; //context.Response.Write("Hello World"); List<Photo> photos = GetPhotos(id,path); DataContractJsonSerializer djson = new DataContractJsonSerializer(photos.GetType()); djson.WriteObject(context.Response.OutputStream, photos); } public List<Photo> GetPhotos(string id,string path) { //获取目录 string localPath = path&#;id &#; "\"; //读取目录下的文件 if (!Directory.Exists(localPath)) return null; string[] files = Directory.GetFiles(localPath); List<Photo> photos = new List<Photo>(); foreach (string file in files) { string filename = file.Substring(file.LastIndexOf('\')&#;1); Photo p = new Photo(); p.name = filename; p.id = id; photos.Add(p); } return photos; } public bool IsReusable { get { return false; } } } public class Photo { public string id; public string name; } }

Unity3D中销毁对象的方式 转载自:

Unity3D获取对象的5中方式 转载自:

封装 UnityEngine.Debug.Log 为Dll ,游戏发布关闭 Log 减少性能消耗 本文参考雨松Mono的文章:

标签: unity jsonobject

本文链接地址:https://www.jiuchutong.com/biancheng/380126.html 转载请保留说明!

上一篇:Unity3d 导入图片 自动修改Texture Type为Sprite (2D and UI) 及设置 Packing Tag为文件夹名(unity怎么导入3d模型)

下一篇:Unity3D中销毁对象的方式(unity销毁预制体)

  • 报废的机器设备怎么处理
  • 股东借钱给公司,公司经营不善倒闭!借款公司要还不
  • 非行政性罚款可以撤销吗
  • 年度利润总额的12%
  • 公司化验室领用丙材料3000元
  • 发票折扣有没有限制
  • 哪些票据可以挂公司名下
  • 呆帐死帐处理
  • 老板在外地怎么辞职
  • ca证书延期不了
  • 委托贷款利息收入怎么开发票
  • win 11bug
  • 事业单位财务预算管理制度
  • 购买固定资产算投资吗
  • 物业公司成本结转方案
  • 合同尾款一般多少
  • 技术服务费增值税发票怎么开
  • php二维码生成代码
  • centos停止发布
  • 企业网银证书费用收费标准
  • 文件夹删除需要管理员权限怎么弄
  • php stream_get_meta_data返回值
  • php数组函数输出《咏雪》里有多少"片"字
  • msqry32.exe进程是什么文件 作用是什么 msqry32进程查询
  • windows7中可以设置控制计算机
  • php数据库连接失败怎么办
  • 新会计准则计入管理费用的税费
  • 商贸企业税收优惠政策
  • PHP:mdecrypt_generic()的用法_Mcrypt函数
  • 固定资产清查盘点报告模板
  • 员工出差机票计入什么科目
  • thinkphp5自定义标签
  • php tr td
  • 微信php接口
  • vue.js.
  • 对公账户走账是怎么回事
  • 劳务公司获奖感言简短
  • 种植中药材公司取名字大全
  • 企业内部培训费用
  • python condition条件变量
  • 金蝶专业版如何打印凭证
  • 收到政府扶贫款如何做分录
  • 收到发票怎么写摘要
  • 公司员工兼职开公司
  • 物流企业货损赔付标准
  • 应收账款借方余额
  • 28栏分次预缴税额是手动填写吗?
  • 银行承兑汇票由谁出票
  • 银行承兑汇票到期日后多久可以承兑
  • 附加税减免政策2020年
  • 跨年多计提的工资如何处理
  • 建筑行业项目经理的岗位职责
  • 融资租赁固定资产利息的账务处理实例
  • 在建工程领用工程物资
  • sql联合主键设置外键
  • 进程管理界面
  • 如何配置samba配置文件
  • freebsd软件包存储库
  • ubuntu安装lamp
  • mac怎么连接校园网wifi
  • runservice.exe - runservice是什么进程 有什么用
  • win7系统连接蓝牙音箱
  • win7如何禁用网卡
  • 如何汉化游戏
  • jquery禁止点击事件
  • css样式的使用
  • shell脚本中执行echo卡住
  • node的全局变量有哪些
  • python字符串大全
  • 深入学习习总书记系列讲话精神
  • 安卓软件测试
  • javascript基础笔记
  • jquery mobile开发环境
  • 基于JAVASCRIPT实现的可视化工具是
  • python如何入门
  • 增值税普通发票需要交税吗
  • 北京 国税局
  • 税务征管科与纳税人有接触吗
  • 9月份公积金什么时候扣
  • 翡翠是否交消费税
  • 免责声明:网站部分图片文字素材来源于网络,如有侵权,请及时告知,我们会第一时间删除,谢谢! 邮箱:opceo@qq.com

    鄂ICP备2023003026号

    网站地图: 企业信息 工商信息 财税知识 网络常识 编程技术

    友情链接: 武汉网站建设