0
我正在尋找如何使用Json.NET反序列化對象的教程,但我找不到任何與我的類似。反序列化與Json.NET
我有一個JSON這樣的:
{
"__ar":1,
"payload":{
"entries":[
{
"uid":100000011980844,
"photo":"",
"type":"user",
"text":"testing",
"path":"testing",
"category":"",
"needs_update":true,
"non_title_tokens":"",
"names":[
"Test"
],
"subtext":"",
"score":0
}
]
}
}
,然後我試圖反序列化這樣的:
var j = JsonConvert.DeserializeObject<People> (json);
然後:
public class People
{
public string __ar { get; set; }
public Payload payload { get; set; }
}
public class Payload
{
public Person entries { get; set; }
}
public class Person
{
public string uid { get; set; }
public string photo { get; set; }
public string type { get; set; }
public string text { get; set; }
public string path { get; set; }
public string category { get; set; }
public string needs_update { get; set; }
public string non_title_tokens { get; set; }
public string subtext { get; set; }
public string score { get; set; }
public List<string> names { get; set; }
}
但事與願違工作,任何人都知道我必須做什麼來解決它?該錯誤消息是:
無法反序列化當前JSON陣列(例如[1,2,3])轉換成類型 「QueryFacebook.Parser +人」,因爲類型需要JSON對象 (例如{「名「:」value「})來正確地反序列化。爲了解決這個問題錯誤 要麼改變JSON來JSON對象(例如{「名稱」:「值」})或 變化反序列化類型到一個數組或一個實現 收集界面(例如ICollection的,IList的)像類型可以從JSON數組中反序列化 的列表。
JsonArrayAttribute也可以添加到該類型迫使它從JSON數組反序列化。 Path'payload.entries',line 1,position 32。 – Crasher