C# json object互转工具

public static T Deserializer<T>(string path)
        {
            try
            {
                System.Xml.XmlDocument xd = new System.Xml.XmlDocument();
                xd.LoadXml(path);
                MemoryStream stream = new MemoryStream();
                xd.Save(stream);

                XmlSerializer xml = new XmlSerializer(typeof(T));
                //序列化对象
                T t = (T)xml.Deserialize(stream);
                stream.Close();
                return t;
            }
            catch (InvalidOperationException)
            {
                throw;
            }
            catch (FileNotFoundException)
            { throw; }
            finally
            {

            }
        }

https://jsonclassgenerator.codeplex.com/

http://json2csharp.com/

posted @ 2013-10-30 19:06  ``炯``  阅读(353)  评论(0编辑  收藏  举报