我以格式
从服务器接收日期数组[{"date":"2016-12-26T00:00:00+08:00"},
{"date":"2016-12-27T00:00:00+08:00"},
{"date":"2016-12-28T00:00:00+08:00"},
{"date":"2016-12-29T00:00:00+08:00"}]
我尝试用JArray.Parse方法解析它们。问题是:方法修改日期到莫斯科TZ(在我的电脑上设置)。因此,解析后,日期看起来像这样
"date": "2016-12-25T19:00:00+03:00"
"date": "2016-12-26T19:00:00+03:00"
"date": "2016-12-27T19:00:00+03:00"
问题是:是否可以防止日期修改?
答案 0 :(得分:1)
var s = "['2016-05-10T13:51:20Z', '2016-05-10T13:51:20+00:00']";
using (JsonReader jsonReader = new JsonTextReader(new StringReader(s))) {
jsonReader.DateParseHandling = DateParseHandling.None;
var array = JArray.Load(jsonReader);
foreach (var item in array) {
var itemValue = item.Value<string>();
Console.WriteLine(itemValue);}
}
输出:
2016-05-10T13:51:20Z
2016-05-10T13:51:20+00:00