Unity自己的json序列化是不支持字典格式的,但是 json .net库,功能很强大,还支持序列化字典.
下载地址:https://download.csdn.net/download/qq_15017279/10358562
下载地址:https://www.newtonsoft.com/json (可能打不开)
Newtonsoft.Json.dll 拖入unity工程。
写下一段简单的序列化 和 反序列化json的代码:
using System.Collections; using System.Collections.Generic; using UnityEngine; using System; using Newtonsoft.Json; public class TestJSON : MonoBehaviour { void Start() { Product product = new Product(); product.dic["键"] = "值"; product.name = "小明"; 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>(); } }