using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.Script.Serialization; namespace WebAPI.Models { public class JsonHelper { private static JsonHelper _Instance; /// /// 单例访问 /// public static JsonHelper Instance { get { if (_Instance == null) { lock (typeof(JsonHelper)) { if (_Instance == null) { _Instance = new JsonHelper(); } } } return _Instance; } } public string ObjToJson(T t) { JavaScriptSerializer js = new JavaScriptSerializer(); return js.Serialize(t); } public T JsonToObj(string strJson) { JavaScriptSerializer js = new JavaScriptSerializer(); return js.Deserialize(strJson); } } }