我有一個JSON像下面,轉換JSON數組到C#對象集合
[
{
"document":
{
"createdDate":1476996267864,
"processedDate":1476996267864,
"taxYear":"2015",
"type":"user_document"
}
},
{
"document":
{
"createdDate":1476998303463,
"processedDate":0,
"taxYear":"2015",
"type":"user_document"
}
}
]
我需要將其轉換爲C#對象。我的對象類型是如下─
public class UserDocument
{
[JsonProperty(PropertyName = "type")]
public string type { get; set; }
[JsonProperty(PropertyName = "taxYear")]
public string taxYear { get; set; }
[JsonProperty(PropertyName = "createdDate")]
public string createdDate { get; set; }
[JsonProperty(PropertyName = "processedDate")]
public string processedDate { get; set; }
}
我用下面的代碼進行反序列化JSON的,但所有UserDocument中屬性爲null
var test = JsonConvert.DeserializeObject<List<UserDocument>>(jsonString);
爲什麼我收到的所有UserDocument中屬性爲null,什麼是錯在這裏?我沒有收到任何錯誤。
你也可以建議一個很好的例子,讓CouchBase queryresult進入.net對象。
'processedDate'和'createdDate'不是字符串。 – RhinoDevel
可能的重複http://stackoverflow.com/questions/4611031/convert-json-string-to-c-sharp-object –
你的json是錯的 – Mostafiz