-1
我有jsonstring:如何從json獲得一些價值而不是roor?
{
"kind": "youtube#videoListResponse",
"etag": "\"NO6QTeg0-3ShswIeqLchQ_mzWJs/o3L50v5R2WwnOWFaoCXQIOzRQt8\"",
"pageInfo": {
"totalResults": 1,
"resultsPerPage": 1
},
"items": [
{
"kind": "youtube#video",
"etag": "\"NO6QTeg0-3ShswIeqLchQ_mzWJs/emOU-eLbb23xAEX_1JcXPAXYJUY\"",
"id": "7eCPp1WLpyA",
"contentDetails": {
"duration": "PT7M10S",
"dimension": "2d",
"definition": "hd",
"caption": "false",
"licensedContent": true
},
"statistics": {
"viewCount": "1603",
"likeCount": "454",
"dislikeCount": "6",
"favoriteCount": "0",
"commentCount": "107"
}
}
]
}
我想時間的值是 「PT7M10S」
我正在編碼:
var obj = JObject.Parse(jsonString);
var url = (string)obj["contentDetails"]["duration"];
return url;
,但我得到的錯誤:對象引用未設置爲一個對象的實例 請大家幫忙!謝謝。
檢查您的JSON - 頂級沒有「contentDetails」... –