datetime json 序列化时丢掉时区
来源:互联网 发布:08总决赛皮尔斯数据 编辑:程序博客网 时间:2024/04/19 12:22
asp.net mvc web api test client 是个好东西,能够直接测试api调用。
但有一点是,生成datetime类型的测试数据时,是带有时区的,导致在调用的时候,反序列化失败。不得不手动修改一下时间的格式。
如下图:
那我们就手动修改一下代码,使其序列化时放弃时区吧
代码修改对比:
位置:
file: $\Areas\HelpPage\SampleGeneration\HelpPageSampleGenerator.cs
class: HelpPageSampleGenerator
Method: private static string TryFormatJson(string str)
LN: 380
[SuppressMessage("Microsoft.Design", "CA1031:DoNotCatchGeneralExceptionTypes", Justification = "Handling the failure by returning the original string.")] private static string TryFormatJson(string str) { try { object parsedJson = JsonConvert.DeserializeObject(str); Newtonsoft.Json.Converters.IsoDateTimeConverter timeFormat = new Newtonsoft.Json.Converters.IsoDateTimeConverter(); timeFormat.DateTimeFormat = "yyyy-MM-dd HH:mm:ss"; return JsonConvert.SerializeObject(parsedJson, Formatting.Indented, timeFormat); } catch { // can't parse JSON, return the original string return str; } }
修改以后生成的示例:
0 0
- datetime json 序列化时丢掉时区
- DateTime数据类型的XML序列化及时区问题(存档)
- 时区设置错误导致DateTime序列化异常
- json序列化时datetime的处理方法
- JavaScriptSerializer 对 DateTime 数据类型的JSON序列化的问题
- JavaScriptSerializer 对 DateTime 数据类型的JSON序列化的问题
- python使用json序列化datetime类型问题处理
- JavaScriptSerializer序列化成Json时DateTime类型数据的处理
- JavaScriptSerializer序列化成Json时DateTime类型数据的处理
- WCF - 跨时区调用时的DateTime
- DateTime类型序列化
- 解决Python自带的json序列化工具不能序列化datetime类型数据问题
- python默认json库处理mysql中datetime,date类型不能序列化json的解决方案
- 用js解析经json序列化后的C#的DateTime类型数据
- DateTime关于时区的学习
- AJAX JSON中日期类型DateTime格式化的序列化自定义对象以及自定义类型参数的问题处理
- 丢掉
- 序列化和json
- C++实验5-数组分离
- Java笔试面试题整理第五波
- Spring AOP 之 通知、连接点、切点、切面。
- SQL构建特征--入门篇
- 使用zlib解压.apk/.zip文件(Windows&Ubuntu)
- datetime json 序列化时丢掉时区
- c++第5次作业
- 浅谈Java反射
- 情感分析︱网络公开的免费文本语料训练数据集汇总
- Java 计时器Timer
- HDU 4612 双联通分量+树的直径
- jquery ajax格式
- HDOJ(HDU) 2148 Score(比较、)
- 文档处理技巧:PDF文件怎样简单编辑修改