本帖最后由 icedong 于 2013-12-23 10:20:05 编辑

解决方案 »

  1.   

    Object 类型要可以序列化,用MS提供的方法序列化好好了,读也一样用MS的方法,试试吧
      

  2.   

    System.Web.Script.Serialization;自己造轮子真的那么好玩么?
      

  3.   

    public class Serialization
        {
            /// <summary>
            /// Json序列化
            /// </summary>
            /// <returns></returns>
            public static string Serialize<T>(T obj)
            {
                try
                {
                    MemoryStream ms = new MemoryStream();
                    DataContractJsonSerializer serializer = new DataContractJsonSerializer(typeof(T));
                    serializer.WriteObject(ms, obj);
                    byte[] json = ms.ToArray();
                    ms.Close();
                    return Encoding.UTF8.GetString(json, 0, json.Length);
                }
                catch(Exception ex)
                {
                    Utils.DebugToFile.WriteErr(ex.ToString());
                    return "";
                }
            }
            /// <summary>
            /// Json反序列化
            /// </summary>
            /// <param name="jsonString"></param>
            public static T Deserialize<T>(string jsonString)
            {
                T t = default(T);
                try
                {
                    if (!string.IsNullOrEmpty(jsonString))
                    {
                        DataContractJsonSerializer serializer = new DataContractJsonSerializer(typeof(T));
                        MemoryStream stream = new MemoryStream(Encoding.UTF8.GetBytes(jsonString));
                        Object obj = serializer.ReadObject(stream);
                        t = (T)obj;
                    }
                    return t;
                }
                catch(Exception ex)
                {
                    Utils.DebugToFile.WriteErr(ex.ToString());
                    return t;
                }
            }
        }
      

  4.   

    额不说啥了,请自己google"System.Web.Script.Serialization"
    "json.net"
    "newtonsoft.json"
      

  5.   


    这个不是自己造轮子的问题,这个是由于以前有许多的model没有序列化的头,只有通过这个来处理
      

  6.   


    公司里面对于引用外部的DLL有限制的,如果能用我早用"json.net"、"newtonsoft.json"了System.web.Script.Serialization 这个我在3.5框架中没找到(程序使用的是winform)