我在尝试反序列化此 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 可能是错误的。
这应该适用于您的课程,使用json2csharp http://json2csharp.com/
public class Doc
{
public string enID { get; set; }
public string startDate { get; set; }
public string bName { get; set; }
public string pName { get; set; }
public List<string> UName { get; set; }
public List<string> agent { get; set; }
}
public class Response
{
public int numfound { get; set; }
public int start { get; set; }
public List<Doc> docs { get; set; }
}
public class ResponseRoot
{
public Response response { get; set; }
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)