using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Web;
namespace KJD_Web.Utils
{
public class JsonUtils
{
///
/// 反序列化Json字符串生成对象实体
///
/// 对象类型
/// json字符串
/// 对象实体
public static T DeserializeJsonToObject(string jsonStr) where T : class
{
try
{
JsonSerializer serializer = new JsonSerializer();
StringReader sr = new StringReader(jsonStr);
object obj = serializer.Deserialize(new JsonTextReader(sr), typeof(T));
T t = obj as T;
return t;
}
catch
{
return null;
}
}
public static string SerializerObjectToString(object obj)
{
try
{
string str = JsonConvert.SerializeObject(obj, Formatting.None);
return str;
}
catch
{
return null;
}
}
}
}