我試圖從Google API(YT)獲取信息。我需要從Google的API中獲取videoId。無法從C#上的JSON獲取良好信息
因此,我下載了JSON頁面,試圖反序列化我的結果,但他不工作。
這是JSON結果
{
"kind": "youtube#playlistItemListResponse",
"etag": "\"m2yskBQFythfE4irbTIeOgYYfBU/E6IhaTG5XEbqo_uSYhCcIvQhtwY\"",
"nextPageToken": "CDIQAA",
"pageInfo": {
"totalResults": 180,
"resultsPerPage": 50
},
"items": [
{
"kind": "youtube#playlistItem",
"etag": "\"m2yskBQFythfE4irbTIeOgYYfBU/0cAZGJiF62yaNO7GwJlJBsc7DqY\"",
"id": "UExNQzlLTmtJbmNLdFB6Z1ktNXJtaHZqN2ZheDhmZHhvai41RDlFNzlCQjE5NzcyQTYx",
"snippet": {
"publishedAt": "2016-05-19T13:47:40.000Z",
"channelId": "UCs72iRpTEuwV3y6pdWYLgiw",
"title": "Katy Perry - Dark Horse (Official) ft. Juicy J",
"description": "Bla bla bla",
},
"channelTitle": "#RedMusic: Just Hits",
"playlistId": "PLMC9KNkIncKtPzgY-5rmhvj7fax8fdxoj",
"position": 0,
"resourceId": {
"kind": "youtube#video",
"videoId": "0KSOMA3QBU0"
}
}
},
這是我採取的VideoID的
JObject jObj = (JObject)JsonConvert.DeserializeObject(x.Result);
foreach (var item in jObj["items"])
{
string title = item["videoId"].ToString();
}
代碼當我開始我的應用我有System.NullReferenceException錯誤。
我的問題在哪裏?
感謝
請檢查您的JSON示例 - 我懷疑你沒有正確複製並粘貼它,因爲後面有一個怪異的逗號「 – mjwills