【发布时间】:2015-04-18 16:22:17
【问题描述】:
好吧,首先,答案可能很简单……但经过 45 分钟的尝试和谷歌搜索后,我还是想不通!
所以我在让这个 Json 正确解析时遇到了一些问题。我用http://json2csharp.com/ 创建了这些类,只是它没有告诉我解析它的代码。
我目前的课程:
public class Representations
{
public string thumb { get; set; }
public string large { get; set; }
public string full { get; set; }
}
public class Search
{
public string id { get; set; }
public string file_name { get; set; }
public Representations representations { get; set; }
}
public class SearchQuery
{
public List<Search> search { get; set; }
public int total { get; set; }
}
JSON:
{
"search": [
{
"id": "0300",
"file_name": "0300.JPG",
"representations": {
"thumb": "thumb.jpg",
"large": "large.jpg",
"full": "0300.jpg"
},
},
{
"id": "0000",
"file_name": "0000.JPG",
"representations": {
"thumb": "thumb.jpg",
"large": "large.jpg",
"full": "0000.jpg"
},
},
{
"id": "0d00",
"file_name": "0d00.JPG",
"representations": {
"thumb": "thumb.jpg",
"large": "large.jpg",
"full": "0d00.jpg"
},
}
],
"total": 3
}
和代码:
searchresults = JsonConvert.DeserializeObject<List<SearchQuery>>(JSONCode);
【问题讨论】: