You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
52 lines
1.1 KiB
52 lines
1.1 KiB
8 months ago
|
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;
|
||
|
/// <summary>
|
||
|
/// 单例访问
|
||
|
/// </summary>
|
||
|
public static JsonHelper Instance
|
||
|
{
|
||
|
get
|
||
|
{
|
||
|
if (_Instance == null)
|
||
|
{
|
||
|
lock (typeof(JsonHelper))
|
||
|
{
|
||
|
if (_Instance == null)
|
||
|
{
|
||
|
_Instance = new JsonHelper();
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
return _Instance;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
|
||
|
public string ObjToJson<T>(T t)
|
||
|
{
|
||
|
|
||
|
JavaScriptSerializer js = new JavaScriptSerializer();
|
||
|
|
||
|
return js.Serialize(t);
|
||
|
|
||
|
}
|
||
|
|
||
|
public T JsonToObj<T>(string strJson)
|
||
|
{
|
||
|
|
||
|
JavaScriptSerializer js = new JavaScriptSerializer();
|
||
|
|
||
|
return js.Deserialize<T>(strJson);
|
||
|
|
||
|
}
|
||
|
}
|
||
|
}
|