iphonejsonparsingjsonkit

How to parse json ki typical format in iphone


I am trying to parse json. but not able to get correct key. I am using JSONKIT. Below is the json data.SO i am trying to get CONTENT pls help me how to do this.

`{
"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"
            }
        }

] } }`

SO i am trying to get CONTENT pls help me how to do this.


Solution

  • Sample Code :

    NSDictionary *content = [[[[yourJSONResponseDict objectForKey:@"data"] objectForKey:@"items"] objectAtIndex:0] objectForKey:@"content"];
    NSLog(@"Content :: %@",content);
    

    Explanation :

    //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"];