这是代码:
var jss = new JavaScriptSerializer();
GResponse dict = jss.Deserialize<GResponse>(jsonText);
这些是类:
public class GResponse
{
public List<GResponseData> responseData { get; set; }
public string responseDetails { get; set; }
public int responseStatus { get; set; }
}
public class GResponseData
{
public List<GResult> results { get; set; }
public List<GCursor> cursor { get; set; }
}
public class GResult
{
public string GsearchResultClass { get; set; }
public string unescapedUrl { get; set; }
public string url { get; set; }
public string visibleUrl { get; set; }
public string cacheUrl { get; set; }
public string title { get; set; }
public string titleNoFormatting { get; set; }
public string content { get; set; }
}
public class GCursor
{
public string resultCount { get; set; }
public List<GPages> PagesItems { get; set; }
public string estimatedResultCount { get; set; }
public int currentPageIndex { get; set; }
public string moreResultsUrl { get; set; }
public string searchResultTime { get; set; }
}
public class GPages
{
public string start { get; set; }
public int label { get; set; }
}
很长一段时间以来,我一直在尝试反序列化以下 json 字符串但没有成功。
{
"responseData": {
"results": [
{
"GsearchResultClass": "GwebSearch",
"unescapedUrl": "irrelevant",
"url": "irrelevant",
"visibleUrl": "irrelevant",
"cacheUrl": "irrelevant",
"title": "irrelevant",
"titleNoFormatting": "irrelevant",
"content": "irrelevant"
},
{
"GsearchResultClass": "GwebSearch",
"unescapedUrl": "irrelevant",
"url": "irrelevant",
"visibleUrl": "irrelevant",
"cacheUrl": "irrelevant",
"title": "irrelevant",
"titleNoFormatting": "irrelevant",
"content": "irrelevant"
}
],
"cursor": {
"resultCount": "irrelevant",
"pages": [
{
"start": "0",
"label": 1
},
{
"start": "28",
"label": 8
}
],
"estimatedResultCount": "irrelevant",
"currentPageIndex": 0,
"moreResultsUrl": "irrelevant",
"searchResultTime": "0.27"
}
},
"responseDetails": null,
"responseStatus": 200
}
似乎没有出现任何错误,但是当我检查 dict.responseData.Count 时,由于某种原因它总是等于 0。提前致谢!