0
我一直在使用一個服務,返回一個數組裏面的數組和JSON文件。 第二層數組的問題是我似乎無法使用它。 的JSON看起來是這樣的:JSON與System.Web.Helpers中的多個圖層
{
"section": "U.S.",
"subsection": "Politics",
"title": "To Understand Clinton’s Moment, Consider That It Came 32 Years After Ferraro’s",
"abstract": "A look back to when Geraldine A. Ferraro was on the Democratic ticket in 1984 can tell a lot about how the country has changed, and how it has not.",
"url": "urlLocation",
"byline": "By ALISON MITCHELL",
"item_type": "Article",
"updated_date": "2016-06-11T13:17:01-04:00",
"created_date": "2016-06-11T13:17:05-04:00",
"published_date": "2016-06-12T00:00:00-04:00",
"material_type_facet": "",
"kicker": "",
"des_facet": [
"Presidential Election of 2016",
"Women and Girls"
],
"org_facet": [],
"per_facet": [
"Clinton, Hillary Rodham",
"Ferraro, Geraldine A"
],
"geo_facet": [],
"multimedia": [
{
"url": "urlLocation",
"format": "Standard Thumbnail",
"height": 75,
"width": 75,
"type": "image",
"subtype": "photo",
"caption": "Geraldine A. Ferraro at a hearing of the Democratic national convention’s platform committee in 1984, the year she became the first woman selected to be a major party’s vice presidential nominee.",
"copyright": "George Tames/The New York Times"
},
{
"url": "urlLocation",
"format": "thumbLarge",
"height": 150,
"width": 150,
"type": "image",
"subtype": "photo",
"caption": "Geraldine A. Ferraro at a hearing of the Democratic national convention’s platform committee in 1984, the year she became the first woman selected to be a major party’s vice presidential nominee.",
"copyright": "George Tames/The New York Times"
},
{
"url": "urlLocation",
"format": "Normal",
"height": 127,
"width": 190,
"type": "image",
"subtype": "photo",
"caption": "Geraldine A. Ferraro at a hearing of the Democratic national convention’s platform committee in 1984, the year she became the first woman selected to be a major party’s vice presidential nominee.",
"copyright": "George Tames/The New York Times"
},
{
"url": "urlLocation",
"format": "mediumThreeByTwo210",
"height": 140,
"width": 210,
"type": "image",
"subtype": "photo",
"caption": "Geraldine A. Ferraro at a hearing of the Democratic national convention’s platform committee in 1984, the year she became the first woman selected to be a major party’s vice presidential nominee.",
"copyright": "George Tames/The New York Times"
},
{
"url": "urlLocation",
"format": "superJumbo",
"height": 1364,
"width": 2048,
"type": "image",
"subtype": "photo",
"caption": "Geraldine A. Ferraro at a hearing of the Democratic national convention’s platform committee in 1984, the year she became the first woman selected to be a major party’s vice presidential nominee.",
"copyright": "George Tames/The New York Times"
}
],
"short_url": "urlLocation"
}
我試圖訪問它是這樣的:
NewsArticle newsArticle = new NewsArticle();
newsArticle.category = data.results[counter].section;
newsArticle.title = data.results[counter].title;
newsArticle.fullText = data.results[counter][email protected];
DynamicJsonArray multimedia = data.results[counter].multimedia;
newsArticle.image = multimedia[0].url;
return_value.Add(newsArticle);
我得到一個「索引數組的範圍之外。」 「多媒體」陣列上的例外。我的語法有什麼問題嗎?
使用調試器,您可能沒有正確反序列化它。 –
什麼是代碼中的'counter'?請提供您用於反序列化JSON的代碼。 – rpeshkov
我正在使用Sytem.Web.Helper庫。在JSON文件的根目錄中給出了這個文件中有多少條目,我將它們存儲在計數器變量中。 – Deadwalker