[英]Null Object-DeSerializing JSON C#
返回 object:
{
"_expands": [],
"size": 3,
"start": 3,
"limit": 3,
"isLastPage": false,
"_links": {
"base": "http://host:port/context/rest/desk",
"context": "context",
"next": "http://host:port/context/rest/desk",
"prev": "http://host:port/context/rest/desk"
},
"values": [
{
"status": "Waiting for Customer",
"statusDate": {
"iso8601": "2015-10-08T14:05:00+0700",
"polaris": "2015-10-08T14:05:00.000+0700",
"friendly": "Today 14:05 PM",
"epochMillis": 1444287900000
}
},
{
"status": "Waiting for Support",
"statusDate": {
"iso8601": "2015-10-08T14:01:00+0700",
"polaris": "2015-10-08T14:01:00.000+0700",
"friendly": "Today 14:01 PM",
"epochMillis": 1444287660000
}
},
{
"status": "Waiting for Customer",
"statusDate": {
"iso8601": "2015-10-08T14:00:00+0700",
"polaris": "2015-10-08T14:00:00.000+0700",
"friendly": "Today 14:00 PM",
"epochMillis": 1444287600000
}
}
]
}
课程:
public class polarisState
{
public string[] expands { get; set; }
public int size { get; set; }
public int start { get; set; }
public int limit { get; set; }
public bool isLastPage { get; set; }
public _links links { get; set; }
public values[] values { get; set; }
}
public class _links
{
//public string base {get; set;}
public string context { get; set; }
public string next { get; set; }
public string prev { get; set; }
}
public class values
{
public string status { get; set; }
public statusDate statusDate { get; set; }
}
public class statusDate
{
public string iso8601 { get; set; }
public string polaris { get; set; }
public string friendly { get; set; }
public int epochMillis { get; set; }
}
下面的代码:
if (resp2.IsSuccessStatusCode)
{
var values = JsonConvert.DeserializeObject<JiraState>(resp2.Content.ReadAsStringAsync().Result); }
您应该将 class polarisState 更改为
public class polarisState
{
public List<string> expands { get; set; }
public int size { get; set; }
public int start { get; set; }
public int limit { get; set; }
public bool isLastPage { get; set; }
public _links links { get; set; }
public List<values> values { get; set; }
}
数组到列表。 然后将 statusDate 更改为:
public class statusDate
{
public string iso8601 { get; set; }
public string polaris { get; set; }
public string friendly { get; set; }
public long epochMillis { get; set; }
}
将 epochMillis 从 int 更改为 long 值类型。 完成。
使用异步方法并更改代码如下:
var content = await resp2.Content.ReadAsStringAsync();
var values = JsonConvert.DeserializeObject<polarisState>(content);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.