Unity3D LitJson 使用方法
来源:互联网 发布:mac移动硬盘无法读取 编辑:程序博客网 时间:2024/05/29 16:29
原创文章如需转载请注明:转载自 脱莫柔Unity3D学习之旅 QQ群:【Unity3D(AR/VR) 334163814】【Unity3D(游戏) 119706192】 本文链接地址: LitJson 使用方法
119706192-QQ群共享提供下载
对象与Json互转:
void OnGUI() { if (GUI.Button(new Rect(10,10,100,20),"ClassToJson")) { ClassToJson(); } if (GUI.Button(new Rect(10, 40, 100, 20), "JsonToClass")) { JsonToClass(); } } string JsonString; public void ClassToJson() { teseClass temp = new teseClass(); temp.name = "名字"; temp.age = 22; temp.isMan = true; temp.testList = new List<int>() { 3, 6, 9 }; JsonString = JsonMapper.ToJson(temp); //Log Debug.Log("ClassToJson:" + JsonString); } public void JsonToClass() { teseClass temp = JsonMapper.ToObject<teseClass>(JsonString); //Log string log = "name:" + temp.name + ":" + temp.age; if (temp.isMan) log += "|男|";else log += "|女|"; log += "testList{"; for (int i = 0; i < temp.testList.Count; i++) { if (i!= 0) log += ","; log += temp.testList[i].ToString(); } log += "}"; Debug.Log(log); } public class teseClass { public string name; public int age; public bool isMan; public List<int> testList; }输出结果:
public class LitJsonTest : MonoBehaviour { void OnGUI() { int y = 10; GUI.Label(new Rect(10,y,1000,30),strJson); y += 30; if( GUI.Button(new Rect(10,y,100,30),"StrToJson")) { StringToJson(strJson); } y += 30; if (GUI.Button(new Rect(10, y, 100, 30), "ClassToJson")) { ClassToJson(); } y += 30; GUI.Label(new Rect(10, y, 1000, 30), PJsonStr); y += 30; } string strJson = "{'name':'testName','id':10,'items':[{'itemid':1001,'itemname':'hello'},{'itemid':1002,'itemname':'hello2'}]}"; void StringToJson(string str) { JsonData jd = JsonMapper.ToObject(str); string name = (string)jd["name"]; long id = (long)jd["id"]; int itemCnt = jd["items"].Count; Debug.Log("name:" + name); Debug.Log("id:" + id); Debug.Log("itemCnt:" + itemCnt); for (int i = 0; i < itemCnt; i++) { JsonData jdItem = jd["items"][i]; int itemid = (int)jdItem["itemid"]; string itemName = (string)jdItem["itemname"]; Debug.Log(itemid + ":" + itemName); } }}
1.StringToJson输出结果
1 0
- Unity3D LitJson 使用方法
- unity3d LitJson 各种嵌套
- Unity3D中LitJson使用
- Unity3d LitJson 的使用
- C# litJson 使用方法
- C# litJson 使用方法
- Unity3d之LitJson例子解析
- UNITY3D 使用 litjson 制作数据表
- Unity3D LitJSON 插件使用教程
- JSON库LitJSON的使用方法
- unity3d 使用LitJson解析 JSON格式数据
- Unity3d之LitJson例子解析+XML
- 【Unity3D】LitJson序列化中文字符
- litjson
- Litjson
- LitJson
- 【Unity开发】Unity3d之MiniJson与LitJson之间的较量
- Unity3d使用LitJson解析服务器上的JSON
- java语法变量、继承变量和继承方法
- PAT3-04 一元多项式的乘加
- 存储器的分类
- Win8.1/Win8 系统下安装Oracle 10g 提示“程序异常终止,发生未知错误”的解决方法
- 用 VLC 显示 树莓派摄像头 H264 裸流
- Unity3D LitJson 使用方法
- JavaScript : var的意义
- 黑马程序员_学习笔记第25天——正则表达式
- Java RMI之HelloWorld 与 Java简单实现RPC
- 【Compute Vision】Viewing Computer Vision from a Bigger Picture
- C++返回值
- 华为面试 失败总结
- GDB调试子进程
- Linux命令学习之--cat