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