【发布时间】:2013-11-21 22:28:19
【问题描述】:
我在这里尝试反序列化此 JSON 时遇到问题:
{
"response": {
"numfound": 1,
"start": 0,
"docs": [
{
"enID": "9999",
"startDate": "2013-09-25",
"bName": "XXX",
"pName": "YYY",
"UName": [
"ZZZ"
],
"agent": [
"BobVilla"
]
}
]
}
}
我为此创建的类是:
public class ResponseRoot {
public Response response;
}
public class Response {
public int numfound { get; set; }
public int start { get; set; }
public Docs[] docs;
}
public class Docs {
public string enID { get; set; }
public string startDate { get; set; }
public string bName { get; set; }
public string pName { get; set; }
public UName[] UName;
public Agent[] agent;
}
public class UName {
public string uText { get; set; }
}
public class Agent {
public string aText { get; set; }
}
但是,每当我打电话时:
ResponseRoot jsonResponse = sr.Deserialize<ResponseRoot>(jsonString);
jsonResponse 最终为 null 并且 JSON 未被反序列化。我似乎无法解释为什么我的类可能不适合这个 JSON。
【问题讨论】:
-
此外,我收到此错误:无法将“System.String”类型的对象转换为“UName”类型
-
Docs上的UName和agent成员不应该是字符串数组吗? -
uname 和 agent 看起来像示例 json 中的字符串列表。
-
你试过json2csharp.com吗?
-
json2csharp.com 真的是 g8 :) 谢谢@L.B
标签: c# json deserialization