Unity3D研究院之Json序列化字典

栏目: 编程语言 · 发布时间: 7年前

内容简介:Unity3D研究院之Json序列化字典

Unity自己的json序列化是不支持字典格式的。无意间发现了一个全新的json .net库,功能很强大,还支持序列化字典推荐给大家。

http://www.newtonsoft.com/json

点击下载,zip. 解压后,把bin/net20/Newtonsoft.Json.dll 拖入unity工程。

写下一段简单的序列化 反序列化json的代码

usingSystem.Collections;
usingSystem.Collections.Generic;
usingUnityEngine;
usingSystem;
usingNewtonsoft.Json;
 
public class Test : MonoBehaviour {
 
 void Start()
 {
 
 Productproduct = new Product();
 product.dic ["字典key"] = "字典Value";
 product.name="我是雨松MOMO";
 string json = JsonConvert.SerializeObject(product);
 
 Product m = JsonConvert.DeserializeObject<Product>(json);
 
 Debug.Log (json);
 Debug.Log (m.name);
 }
 
 
 public class Product 
 {
 public string name;
 public Dictionary<string,string> dic=new Dictionary<string, string>();
 }
 
}

Unity3D研究院之Json序列化字典

用起来还是很方便的。支持复杂的嵌套,各种数据类型。大家可以去摸索。还有不用像unity那样每个序列话的对象还要写多一个[System.Serializable]标签。

工具 的缺点就是dll有点大。

欢迎大家一起测试~


以上就是本文的全部内容,希望本文的内容对大家的学习或者工作能带来一定的帮助,也希望大家多多支持 码农网

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

Rationality for Mortals

Rationality for Mortals

Gerd Gigerenzer / Oxford University Press, USA / 2008-05-02 / USD 65.00

Gerd Gigerenzer's influential work examines the rationality of individuals not from the perspective of logic or probability, but from the point of view of adaptation to the real world of human behavio......一起来看看 《Rationality for Mortals》 这本书的介绍吧!

HTML 压缩/解压工具
HTML 压缩/解压工具

在线压缩/解压 HTML 代码

随机密码生成器
随机密码生成器

多种字符组合密码