/// <summary> /// Json 序列化工具类 /// </summary> public class SerializeJsonUtility { /// <summary> /// 根据一个JSON,得到一个类 /// </summary> public static T JsonToClass<T>(string json) where T : class { T t = JsonReader.Deserialize<T>(json); return t; } /// <summary> /// 根据一个JSON的文件Resources地址,得到一个类 /// </summary> public static T AddressToClass<T>(string txtAddress) where T : class { TextAsset jsonData = Resources.Load(txtAddress) as TextAsset; return JsonToClass<T>(jsonData.text); } /// <summary> /// 将JSON转换为一个类数组 /// </summary> public static T[] JsonToClasses<T>(string json) where T : class { //Debug.Log(json); T[] list = JsonReader.Deserialize<T[]>(json); return list; } /// <summary> /// 将JSON转换为一个类集合 /// </summary> public static List<T> JsonToClasseList<T>(string json) where T : class { T[] ary = JsonReader.Deserialize<T[]>(json); List<T> list = new List<T>(); if (ary!=null && ary.Length >0) { for (int i = 0; i < ary.Length; i++) { list.Add(ary[i]); } } return list; } /// <summary> /// 给Json文件的Resources地址。转换为一个类数组 /// </summary> public static T[] AddressToClasses<T>(string txtAddress) where T : class { TextAsset jsonData = Resources.Load(txtAddress) as TextAsset; return JsonToClasses<T>(jsonData.text); } }