LitJson使用范例
来源:互联网 发布:实变函数和实分析 知乎 编辑:程序博客网 时间:2024/06/05 15:09
LitJson使用范例
在Unity里面使用需要一个LitJson插件,需要放在Plugins目录下面,如下:
LitJson使用代码块范例:
using System.Collections;using System.Collections.Generic;using UnityEngine;using LitJson;public class ListJsonDemo : MonoBehaviour{ private List<Role> roleList; private List<Role> parsedRoleList; void Start() { roleList = new List<Role>(); roleList.Add(new Role { id = 1, name = "刘德华", lv = 100, hp = 1000 }); roleList.Add(new Role { id = 2, name = "黎明", lv = 44, hp = 1000 }); roleList.Add(new Role { id = 3, name = "张学友", lv = 66, hp = 200 }); ///序列化 ///1. string jsonStr = JsonMapper.ToJson(roleList); print(jsonStr); ///2. JsonData data = new JsonData(); data["id"] = 2; data["name"] = "成龙"; data["films"] = new JsonData(); data["films"].Add("警察故事1"); data["films"].Add("警察故事2"); data["films"].Add("警察故事3"); data["films"].Add("醉拳"); print(data.ToJson()); ///反序列化 parsedRoleList = new List<Role>(); print("===================="); JsonData dddd = JsonMapper.ToObject(jsonStr); foreach (JsonData item in dddd) { print(item.ToJson()); Role r = JsonMapper.ToObject<Role>(item.ToJson()); ///此方法内部一定用了反射, /// parsedRoleList.Add(r); } print(parsedRoleList[0].name); }}public class Role{ public int id; public string name; public int age; public int lv; //等级 public int hp;}
LitJson插件下载链接:https://pan.baidu.com/s/1dESlHaL 密码:mge4
阅读全文
0 0
- LitJson使用范例
- LitJson的使用
- LitJson 简单使用心得
- Unity3D中LitJson使用
- LitJson 的使用
- LitJson的使用
- litjson插件的使用
- Unity3d LitJson 的使用
- litjson
- Litjson
- LitJson
- C#使用LitJson解析JSON
- C#使用LitJson解析JSON
- C#使用LitJson解析JSON
- 在android系统使用LitJson
- C#使用LitJson解析JSON
- UNITY3D 使用 litjson 制作数据表
- Unity3D LitJSON 插件使用教程
- spring整合mybatis
- excel中如何将数字转换成文本
- this关键字
- 蓝桥杯 算法提高 身份证号码升级
- python函数
- LitJson使用范例
- RxJava简单入门
- 谷歌账号手机验证失败的一些解决方法
- 为什么写博客
- 在FPGA的ROMIP核中导入由txt建立的coe数据文件并仿真
- 【 Tomcat 】tomcat8.0 基本参数调优配置
- 编译ARToolKit遇到的几个问题
- nodejs elasticsearch基础使用
- 用Java实现约瑟夫问题