c#.net将对象序列化,反序列化json

using System;
using System.Collections.Generic;
using System.Text;

namespace System.Web.Script.Serialization
{
    
// 摘要:
    
//     Provides serialization and deserialization functionality for AJAX-enabled
    
//     applications.
    public class JavaScriptSerializer
    {
        
// 摘要:
        
//     Initializes a new instance of the System.Web.Script.Serialization.JavaScriptSerializer
        
//     class that has no type resolver.
        public JavaScriptSerializer();
        
//
        
// 摘要:
        
//     Initializes a new instance of the System.Web.Script.Serialization.JavaScriptSerializer
        
//     class that has a custom type resolver.
        
//
        
// 参数:
        
//   resolver:
        
//     The custom type-resolver object.
        public JavaScriptSerializer(JavaScriptTypeResolver resolver);

        
// 摘要:
        
//     Gets or sets the maximum length of JSON strings that are accepted by the
        
//     System.Web.Script.Serialization.JavaScriptSerializer class.
        
//
        
// 返回结果:
        
//     The maximum length of JSON strings. The default is 2097152 characters, which
        
//     is equivalent to 4 MB of Unicode string data.
        
//
        
// 异常:
        
//   System.ArgumentOutOfRangeException:
        
//     The property is set to a value that is less than one.
        public int MaxJsonLength { getset; }
        
//
        
// 摘要:
        
//     Gets or sets the limit for constraining the number of object levels to process.
        
//
        
// 返回结果:
        
//     The number of object levels. The default is 100.
        
//
        
// 异常:
        
//   System.ArgumentOutOfRangeException:
        
//     The property is set to a value that is less than one.
        public int RecursionLimit { getset; }

        
// 摘要:
        
//     Converts the given object to the specified type.
        
//
        
// 参数:
        
//   obj:
        
//     The object to convert.
        
//
        
// 类型参数:
        
//   T:
        
//     The type to which obj will be converted.
        
//
        
// 返回结果:
        
//     The object that has been converted to the target type.
        
//
        
// 异常:
        
//   System.InvalidOperationException:
        
//     obj (or a nested member of obj) contains a "__type" property that indicates
        
//     a custom type, but the type resolver that is associated with the serializer
        
//     cannot find a corresponding managed type.  -or- obj (or a nested member of
        
//     obj) contains a “__type” property that indicates a custom type, but the result
        
//     of deserializing the corresponding JSON string cannot be assigned to the
        
//     expected target type.  -or- obj (or a nested member of obj) contains a “__type”
        
//     property that indicates either System.Object or a non-instantiable type (for
        
//     example, an abstract type or an interface).  -or- An attempt was made to
        
//     convert obj to an array-like managed type, which is not supported for use
        
//     as a deserialization target. -or- It is not possible to convert obj to T.
        
//
        
//   System.ArgumentException:
        
//     obj is a dictionary type and a non-string key value was encountered. -or-
        
//     obj includes member definitions that are not available on type T.
        public T ConvertToType<T>(object obj);
        
//
        
// 摘要:
        
//     Converts the specified JSON string to an object of type T.
        
//
        
// 参数:
        
//   input:
        
//     The JSON string to be deserialized.
        
//
        
// 类型参数:
        
//   T:
        
//     The type of the resulting object.
        
//
        
// 返回结果:
        
//     The deserialized object.
        
//
        
// 异常:
        
//   System.ArgumentException:
        
//     The input length exceeds the value of System.Web.Script.Serialization.JavaScriptSerializer.MaxJsonLength.
        
//     -or- The recursion limit defined by System.Web.Script.Serialization.JavaScriptSerializer.RecursionLimit
        
//     was exceeded. -or- input contains an unexpected character sequence. -or-
        
//     input is a dictionary type and a non-string key value was encountered. -or-
        
//     input includes member definitions that are not available on type T.
        
//
        
//   System.ArgumentNullException:
        
//     input is null.
        
//
        
//   System.InvalidOperationException:
        
//     input contains a “__type” property that indicates a custom type, but the
        
//     type resolver associated with the serializer cannot find a corresponding
        
//     managed type. -or- input contains a “__type” property that indicates a custom
        
//     type, but the result of deserializing the corresponding JSON string cannot
        
//     be assigned to the expected target type. -or- input contains a “__type” property
        
//     that indicates either System.Object or a non-instantiable type (for example,
        
//     an abstract types or an interface). -or- An attempt was made to convert a
        
//     JSON array to an array-like managed type that is not supported for use as
        
//     a JSON deserialization target. -or- It is not possible to convert input to
        
//     T.
        public T Deserialize<T>(string input);
        
//
        
// 摘要:
        
//     Converts the specified JSON string to an object graph.
        
//
        
// 参数:
        
//   input:
        
//     The JSON string to be deserialized.
        
//
        
// 返回结果:
        
//     The deserialized object.
        
//
        
// 异常:
        
//   System.ArgumentNullException:
        
//     input is null.
        
//
        
//   System.ArgumentException:
        
//     The input length exceeds the value of System.Web.Script.Serialization.JavaScriptSerializer.MaxJsonLength.
        
//     -or- The recursion limit defined by System.Web.Script.Serialization.JavaScriptSerializer.RecursionLimit
        
//     was exceeded. -or- input contains an unexpected character sequence. -or-
        
//     input is a dictionary type and a non-string key value was encountered. -or-
        
//     input includes member definitions that are not available on the target type.
        
//
        
//   System.InvalidOperationException:
        
//     input contains a “__type” property that indicates a custom type, but the
        
//     type resolver that is currently associated with the serializer cannot find
        
//     a corresponding managed type. -or- input contains a “__type” property that
        
//     indicates a custom type, but the result of deserializing the corresponding
        
//     JSON string cannot be assigned to the expected target type. -or- input contains
        
//     a “__type” property that indicates either System.Object or a non-instantiable
        
//     type (for example, an abstract type or an interface).  -or- An attempt was
        
//     made to convert a JSON array to an array-like managed type that is not supported
        
//     for use as a JSON deserialization target. -or- It is not possible to convert
        
//     input to the target type.
        public object DeserializeObject(string input);
        
//
        
// 摘要:
        
//     Registers a custom converter with the System.Web.Script.Serialization.JavaScriptSerializer
        
//     instance.
        
//
        
// 参数:
        
//   converters:
        
//     An array that contains the custom converters to be registered.
        
//
        
// 异常:
        
//   System.ArgumentNullException:
        
//     converters is null.
        public void RegisterConverters(IEnumerable<JavaScriptConverter> converters);
        
//
        
// 摘要:
        
//     Converts an object to a JSON string.
        
//
        
// 参数:
        
//   obj:
        
//     The object to serialize.
        
//
        
// 返回结果:
        
//     The serialized JSON string.
        
//
        
// 异常:
        
//   System.InvalidOperationException:
        
//     The resulting JSON string exceeds the value of System.Web.Script.Serialization.JavaScriptSerializer.MaxJsonLength.
        
//     -or- obj contains a circular reference. A circular reference occurs when
        
//     a child object has a reference to a parent object, and the parent object
        
//     has a reference to the child object.
        
//
        
//   System.ArgumentException:
        
//     The recursion limit defined by System.Web.Script.Serialization.JavaScriptSerializer.RecursionLimit
        
//     was exceeded.
        public string Serialize(object obj);
        
//
        
// 摘要:
        
//     Serializes an object and writes the resulting JSON string to the specified
        
//     System.Text.StringBuilder object.
        
//
        
// 参数:
        
//   obj:
        
//     The object to serialize.
        
//
        
//   output:
        
//     The System.Text.StringBuilder object that is used to write the JSON string.
        
//
        
// 异常:
        
//   System.InvalidOperationException:
        
//     The resulting JSON string exceeds the value of System.Web.Script.Serialization.JavaScriptSerializer.MaxJsonLength.
        
//     -or- obj contains a circular reference. A circular reference occurs when
        
//     a child object has a reference to a parent object, and the parent object
        
//     has a reference to the child object.
        
//
        
//   System.ArgumentException:
        
//     The recursion limit defined by System.Web.Script.Serialization.JavaScriptSerializer.RecursionLimit
        
//     was exceeded.
        
//
        
//   System.ArgumentNullException:
        
//     output is null.
        public void Serialize(object obj, StringBuilder output);
    }
}

System.Web.Extensions.dll

原文地址:https://www.cnblogs.com/wucg/p/1824747.html