public string ToJson(object obj, string timeFormat)
{
try
{
IsoDateTimeConverter timeConverter = new IsoDateTimeConverter();
timeConverter.DateTimeFormat = timeFormat;
List<JsonConverter> converters = new List<JsonConverter>();
converters.Add(timeConverter);
JsonSerializerSettings jSetting = new JsonSerializerSettings
{
//排空
//NullValueHandling = NullValueHandling.Ignore,
//时间格式化设置
Converters = converters
};
string json = JsonConvert.SerializeObject(obj, Formatting.Indented, jSetting);
return json;
}
catch (Exception e)
{
return "";
}
}
手机扫一扫
移动阅读更方便
你可能感兴趣的文章