我正在尝试解析json。但无法获得正确的密钥。我正在使用JSONKIT。下面是json数据。我想获取内容请帮助我如何做到这一点。
`{
"apiVersion": "2.1",
"data": {
"updated": "2013-06-13T06:15:22.613Z",
"totalItems": 1000000,
"startIndex": 1,
"itemsPerPage": 25,
"items": [
{
"id": "l2h9kFq3TFQ",
"uploaded": "2013-04-09T15:20:46.000Z",
"updated": "2013-06-11T22:32:56.000Z",
"uploader": "trollinforlaughs",
"category": "Games",
"title": "Funny Fail Compilation 2013",
"description": "by FAIL.nl LOOKING FOR YOUTUBE PARTNERSHIP? http://www.acifinnetwork.com/a/bigshotz \"Extra Tags: \"girls fail compilation\" \"fail compilation 2012\" \"compilatio...",
"thumbnail": {
"sqDefault": "https://i.ytimg.com/vi/l2h9kFq3TFQ/default.jpg",
"hqDefault": "https://i.ytimg.com/vi/l2h9kFq3TFQ/hqdefault.jpg"
},
"player": {
"default": "https://www.youtube.com/watch?v=l2h9kFq3TFQ&feature=youtube_gdata_player",
"mobile": "https://m.youtube.com/details?v=l2h9kFq3TFQ"
},
"content": {
"1": "rtsp://v8.cache7.c.youtube.com/CiILENy73wIaGQlUTLdakH1olxMYDSANFEgGUgZ2aWRlb3MM/0/0/0/video.3gp",
"5": "https://www.youtube.com/v/l2h9kFq3TFQ?version=3&f=videos&app=youtube_gdata",
"6": "rtsp://v8.cache7.c.youtube.com/CiILENy73wIaGQlUTLdakH1olxMYESARFEgGUgZ2aWRlb3MM/0/0/0/video.3gp"
},
"duration": 776,
"aspectRatio": "widescreen",
"rating": 4.463792,
"likeCount": "13094",
"ratingCount": 15121,
"viewCount": 6493167,
"favoriteCount": 0,
"commentCount": 5316,
"accessControl": {
"comment": "allowed",
"commentVote": "allowed",
"videoRespond": "moderated",
"rate": "allowed",
"embed": "allowed",
"list": "allowed",
"autoPlay": "allowed",
"syndicate": "allowed"
}
},
{
"id": "DfznjFrNvf4",
"uploaded": "2013-05-24T19:15:36.000Z",
"updated": "2013-06-10T01:11:01.000Z",
"uploader": "funnymediatv",
"category": "Comedy",
"title": "The Ultimate Fail,Win and Funny pranks Mega Compilation part 96",
"description": "Rate, Share and Subscribe ! Like us on Facebook: https://www.facebook.com/BestFunnyFails Funny Fails Community: https://plus.google.com/u/0/communities/11109...",
"thumbnail": {
"sqDefault": "https://i.ytimg.com/vi/DfznjFrNvf4/default.jpg",
"hqDefault": "https://i.ytimg.com/vi/DfznjFrNvf4/hqdefault.jpg"
},
"player": {
"default": "https://www.youtube.com/watch?v=DfznjFrNvf4&feature=youtube_gdata_player",
"mobile": "https://m.youtube.com/details?v=DfznjFrNvf4"
},
"content": {
"1": "rtsp://v6.cache2.c.youtube.com/CiILENy73wIaGQn-vc1ajOf8DRMYDSANFEgGUgZ2aWRlb3MM/0/0/0/video.3gp",
"5": "https://www.youtube.com/v/DfznjFrNvf4?version=3&f=videos&app=youtube_gdata",
"6": "rtsp://v6.cache2.c.youtube.com/CiILENy73wIaGQn-vc1ajOf8DRMYESARFEgGUgZ2aWRlb3MM/0/0/0/video.3gp"
},
"duration": 619,
"aspectRatio": "widescreen",
"rating": 4.6666665,
"likeCount": "220",
"ratingCount": 240,
"viewCount": 55915,
"favoriteCount": 0,
"commentCount": 28,
"accessControl": {
"comment": "allowed",
"commentVote": "allowed",
"videoRespond": "moderated",
"rate": "allowed",
"embed": "allowed",
"list": "allowed",
"autoPlay": "allowed",
"syndicate": "allowed"
}
}
] } }`
所以我试图获取内容请帮助我如何做到这一点。
答案 0 :(得分:0)
示例代码:
NSDictionary *content = [[[[yourJSONResponseDict objectForKey:@"data"] objectForKey:@"items"] objectAtIndex:0] objectForKey:@"content"];
NSLog(@"Content :: %@",content);
说明:
//1. This will give you the "Value" for key "data".
NSDictionary *data = [yourJSONResponseDict objectForKey:@"data"];
//2. This will give you the "Value" for key "items" which is inside "data" Dictionary.
NSArray *items = [data objectForKey:@"items"];
//3. This will give you the First Object of "items" Array which is a Dictionary.
NSDictionary *itemObject = [items objectAtIndex:0];
//4. This will give you your Final Component named "Content" which is a Dictionary also.
NSArray *content = [itemObject objectForKey:@"content"];