2

I have a JSON POST Request and it is returning the below description to me from this..

 NSDictionary *dicData = [NSJSONSerialization JSONObjectWithData:responseData options:kNilOptions error:&error];

This is the NSLog...

I am trying to populate an additional NSMutableArray with just the thumbnail. But when I print out all keys the only key I get is 'mediaList'

Aren't 'full size and thumbnail other Keys?

2016-10-31 13:56:16.551008 MuzikLive MuzikLive[1444:794721] The dicData has this in it {
    mediaList =     (
                {
            fullsize = "/getMedia?file=/LivePic-19700101_014950899.jpg";
            thumbnail = "/getMedia?file=/thumbs/LivePic-19700101_014950899.jpg";
        },
                {
            fullsize = "/getMedia?file=/LivePic-19700101_014952658.jpg";
            thumbnail = "/getMedia?file=/thumbs/LivePic-19700101_014952658.jpg";
        },
                {
            fullsize = "/getMedia?file=/LivePic-19700101_014954431.jpg";
            thumbnail = "/getMedia?file=/thumbs/LivePic-19700101_014954431.jpg";
        },
 {
            fullsize = "/getMedia?file=/LiveVid-19700101_025111.mp4";
            thumbnail = "/getMedia?file=/thumbs/LiveVid-19700101_025111.jpg";
        }
    );
}
2
  • dictData has one key-value ( mediaList is a key and its value is an array). You have to iterate that array to get the values of thumbnail. Commented Oct 31, 2016 at 18:11
  • Thanks for this as well, clarified a lot for me. Commented Oct 31, 2016 at 18:30

2 Answers 2

2

Aren't 'full size and thumbnail other Keys - they are, but nested.
The top level dictionary dicData contains only data for the key mediaList.
The associated data is:

(
    {
        fullsize = "/getMedia?file=/LivePic-19700101_014950899.jpg";
        thumbnail = "/getMedia?file=/thumbs/LivePic-19700101_014950899.jpg";
    },
            {
        fullsize = "/getMedia?file=/LivePic-19700101_014952658.jpg";
        thumbnail = "/getMedia?file=/thumbs/LivePic-19700101_014952658.jpg";
    },
            {
        fullsize = "/getMedia?file=/LivePic-19700101_014954431.jpg";
        thumbnail = "/getMedia?file=/thumbs/LivePic-19700101_014954431.jpg";
    },
    {
        fullsize = "/getMedia?file=/LiveVid-19700101_025111.mp4";
        thumbnail = "/getMedia?file=/thumbs/LiveVid-19700101_025111.jpg";
    }
)

which is an array of other nested dictionaries which in turn each contain two keys fullsize and thumbnail.

You therefore have to

  • get the value for mediaList out of dicData
  • treat that data as an array
  • get each of the array entries
  • treat them as dictionaries
  • extract fullsize and thumbnail out of them
Sign up to request clarification or add additional context in comments.

Comments

1

According to this JSON view you should parse the dictionary according to this..

In Your Scenario parse your JSON dictionary like this.

@property(strong,nonatomic) NSMutableArray *arrayOfThumbnail;

-(void)parseJSONDict:(NSDictionary *)dicData{

    //Alloc new memory to your mutable Array
    self.arrayOfThumbnail = [[NSMutableArray alloc]init]; 
    // Get the array from json who key is "mediaList"
    NSArray = [dicData objectForKey:@"mediaList"];

    for(int index=0;index < array.count ; index++){
        /*In Loop this Array has a dictionary at every index
        {} curly braces in JSON indicates a Dictionary*/

            NSDictionary *dict = [array objectAtIndex:index];

         // Now Fetch the Thumbnail String by providing the keyword to the dictionary at that index

            NSString *thumbnailString = [dict objectForKey:@"thumbnail"];

            [self.arrayOfThumbnail addObject:thumbnailString];
        }


    }

1 Comment

Good morning , that is great !! Much appreciated . all you that helped me. Have a great day.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.