ASP.NET3.5 JSON字符串反序列化
使用VS2008扩展方法去将一个JSON字符串反序列化成对象集合
其实是对上一篇中的 JSONHelper 类 改造
using System.Web.Script.Serialization; using System.Collections.Generic; public static class JSONHelperModule { static JSONHelperModule(){} /// <summary> /// 将对象序列化为JSON字符串 /// </summary> /// <param name="obj">要序列化的对象</param> /// <returns>JSON字符串</returns> public static string ToJSONString(this object obj) { JavaScriptSerializer Serializer = new JavaScriptSerializer(); return Serializer.Serialize(obj); } /// <summary> /// 将JSON字符串反序列化 /// </summary> /// <typeparam name="T">类型</typeparam> /// <param name="JsonStr">JSON字符串</param> /// <returns>T类型List</returns> public static List<T> JSONStringToList<T>(this string JsonStr) { JavaScriptSerializer Serializer = new JavaScriptSerializer(); List<T> objs = Serializer.Deserialize<List<T>>(JsonStr); return objs; } }