object To json
public static string ObjectToJson(object obj)
{
JsonSerializerSettings jss = new JsonSerializerSettings(); IsoDateTimeConverter timeConverter = new IsoDateTimeConverter();
timeConverter.DateTimeFormat = "yyyy'-'MM'-'dd' 'HH':'mm':'ss";//日期转化为字符串类型 jss.ContractResolver = new LowercaseContractResolver();//Column转化为小写
jss.Converters.Add(timeConverter); return JsonConvert.SerializeObject(obj, Newtonsoft.Json.Formatting.Indented, jss);
}
json To object
public static object JsonToObject(string jsonString, object obj)
{
return JsonConvert.DeserializeObject(jsonString, obj.GetType());
}