Newtonsoft.Json处理日期问题

    用Newtonsoft.Json转换json,可是如果数据库是日期类型转换出来之后变成了"\/Date(1269582661683+0800)\/"这样的格式

   

   下面是解决方案:

        List listUser = UserInfoManage.GetUserInfoBySQL("Select Top 5 * From Userinfo");
        IsoDateTimeConverter timeConverter = new IsoDateTimeConverter();
        //这里使用自定义日期格式,如果不使用的话,默认是ISO8601格式    
        timeConverter.DateTimeFormat = "yyyy'-'MM'-'dd' 'HH':'mm':'ss";
        //listUser是准备转换的对象
        string ResJsonStr = JsonConvert.SerializeObject(listUser, Formatting.Indented, timeConverter);
        return ResJsonStr;

 

 [{
    "Id": 6,
    "UserId": "food6",
    "UserPwd": "f0000",
    "State": true,
    "RegTime": "2009-10-16 16:59:59",
    "ComeInt": 1,
    "RegAdmin": "1",
    "IsVip": 0,
    "IsPhoneSale": 0,
    "IsA": 0,
    "IsB": 0,
    "A": "",
    "B": "",
    "C": ""
  }]

转载于:https://www.cnblogs.com/qixuejia/archive/2010/07/24/1784139.html

你可能感兴趣的:(Newtonsoft.Json处理日期问题)