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 ""; } }