[英]Deserialize json utc date from jira api to .net datetime
Jira is responding to a GET Request with this date time format: Jira 正在使用此日期时间格式响应 GET 请求:
"2013-09-17T12:07:36.000-0500" “2013-09-17T12:07:36.000-0500”
I've gotten this far: settings.DateTimeFormat = new DateTimeFormat("yyyy-MM-ddTHH:mm:ss.fff");我已经走了这么远: settings.DateTimeFormat = new DateTimeFormat("yyyy-MM-ddTHH:mm:ss.fff");
This is a classical XY-Problem . 这是经典的XY问题 。 ( X would be: how can I process this json response )
( X将是: 我该如何处理这个json响应 )
See how it can be done easily with Json.Net 了解如何使用Json.Net轻松完成
WebClient wc = new WebClient();
string json = wc.DownloadString("https://jira.atlassian.com/rest/api/latest/issue/JRA-9.json");
dynamic jObj = JObject.Parse(json);
DateTime dt = (DateTime)jObj.fields.updated;
Of course, deserializing the json string to concrete classes is also possible. 当然,也可以将json字符串反序列化为具体的类。 In that case you can use this site
在这种情况下,您可以使用此网站
Does this snippet solves your issue? 这个摘要是否可以解决您的问题?
using System.Web.Script.Serialization;
var json = @"{ date : ""2013-09-17T12:07:36.000-0500""}";
var date = new JavaScriptSerializer().Deserialize<Dictionary<string, DateTime>>(json);
试试“yyyy-MM-dd'T'HH:mm:ss.FFFK”
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.