• JsonFX 序列化反序列化


    /// <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);
        }
    }
  • 相关阅读:
    webDriver检索table数据
    C# 遍历枚举
    Java——Iterate through a HashMap
    Java——Read/convert an InputStream to a String
    简单的异步HTTP服务端和客户端
    授信主体查找
    mysql 事务测试
    mysql 替换
    如何查看由EF生成的SQL?
    C# 如何用多字符分割字符串
  • 原文地址:https://www.cnblogs.com/123ing/p/3779815.html
Copyright © 2020-2023  润新知