0
{
    data =     (
                {
            "created_time" = "2011-09-28T07:29:37+0000";
            from =             {
                id = 100002944043966;
                name = "alok sinha";
            };
            height = 500;
            icon = "https://s-static.ak.facebook.com/rsrc.php/v2/yz/r/StEh3RhPvjk.gif";
            id = 114750595299741;
            images =             (
                                {
                    height = 2048;
                    source = "https://fbcdn-sphotos-a.akamaihd.net/hphotos-ak-ash4/s2048x2048/300035_114750595299741_1543248164_n.jpg";
                    width = 2048;
                },
                                {
                    height = 500;
                    source = "https://fbcdn-sphotos-a.akamaihd.net/hphotos-ak-ash4/300035_114750595299741_1543248164_n.jpg";
                    width = 500;
                },
                                {
                    height = 500;
                    source = "https://fbcdn-sphotos-a.akamaihd.net/hphotos-ak-ash4/300035_114750595299741_1543248164_n.jpg";
                    width = 500;
                },
                                {
                    height = 480;
                    source = "https://fbcdn-sphotos-a.akamaihd.net/hphotos-ak-ash4/s480x480/300035_114750595299741_1543248164_n.jpg";
                    width = 480;
                },
                                {
                    height = 320;
                    source = "https://fbcdn-sphotos-a.akamaihd.net/hphotos-ak-ash4/s320x320/300035_114750595299741_1543248164_n.jpg";
                    width = 320;
                },
                                {
                    height = 180;
                    source = "https://fbcdn-photos-a.akamaihd.net/hphotos-ak-ash4/300035_114750595299741_1543248164_a.jpg";
                    width = 180;
                },
                                {
                    height = 130;
                    source = "https://fbcdn-photos-a.akamaihd.net/hphotos-ak-ash4/300035_114750595299741_1543248164_s.jpg";
                    width = 130;
                },
                                {
                    height = 130;
                    source = "https://fbcdn-photos-a.akamaihd.net/hphotos-ak-ash4/s75x225/300035_114750595299741_1543248164_s.jpg";
                    width = 130;
                }
            );
            link = "https://www.facebook.com/photo.php?fbid=114750595299741&set=a.114750591966408.20279.100002944043966&type=1";
            picture = "https://fbcdn-photos-a.akamaihd.net/hphotos-ak-ash4/300035_114750595299741_1543248164_s.jpg";
            position = 1;
            source = "https://fbcdn-sphotos-a.akamaihd.net/hphotos-ak-ash4/300035_114750595299741_1543248164_n.jpg";
            "updated_time" = "2011-09-28T07:29:38+0000";
            width = 500;
        }
    );
    paging =     {
        next = "https://graph.facebook.com/114750591966408/photos?value=1&redirect=1&limit=25&after=MTE0NzUwNTk1Mjk5NzQx";
    };
}

4
  • Are you using SBJSON or any other alternative to parse JSON into an object representation? Commented Jul 9, 2012 at 9:37
  • Your first step would be to get valid JSON... ( and ) are invalid. Equal signs are invalid, semicolons are invalid...is this even JSON? Commented Jul 9, 2012 at 9:42
  • This is parsed JSON printed into NSLog it seems :) Commented Jul 9, 2012 at 9:45
  • @Eugene Right ,now i need to fetch all source url! Commented Jul 9, 2012 at 9:47

4 Answers 4

2
NSArray *jsonArray; // your parsed array

NSDictionary *dict = [jsonArray objectAtIndex:0]; // there might be more of the objects and you might need to put that into a forin cycle, but for simplicity this is an example for an array with only one dictionary in it

NSArray *images = [dict objectForKey:@"images"];

NSMutableArray *links = [NSMutableArray array];

for (NSDictionary *img in images) {
  [links addObject:[img valueForKey:@"source"]];
}

Now links are the array of NSString objects that you need. You can also transform them into NSURLs if you need to.

Sign up to request clarification or add additional context in comments.

Comments

2

Well your array of images is just [jsonObject objectForKey:@"images"] so loop through all of those and take [loopObject objectForKey:@"source"] and lastly, don't forget [jsonObject objectForKey:@"source"]

Comments

1

[yourDictionary objectForKey:@"data"] gives dictionary.

NSDictionary *dictionary = [yourDictionary objectForKey:@"data"]

    NSArray *images = [dictionary objectForKey:@"images"];

          NSMutableArray *sourceUrls = [[NSMutableArray alloc] initWithCapacity:0];

            for (NSDictionary *subDictionary in images]) {

                    [sourceUrls addObject:[subDictioanary objectForKey:@"source"]];
                }

I think it will be helpful to you.

10 Comments

all the value existing at the first index of array!no key is there!
i don't understand what you mean.
In your data, images is key and the values are there for corresponding key(images).
but i m getting null when i try to fetch value corrosponding to images key!have u got any..
NSLog(@"%@",[dictionary objectForKey:@"images"]); Try like it.
|
-1

Include SBJSON parser in your code. Then import SBJson.h in the implementation file. Then Use the below code for it.

NSMutableDictionary *responseDictionary = [yourJsonString JSONValue];
NSArray *imageArray = [responseDictionary objectForKey:@"images"];

NSMutableArray *sourceImage=[[NSMutableArray alloc]init]
for(int i=0;i<[imageArray count];i++){
{
[sourceImage appendString:[[imageArray objectAtIndex:i]objectForKey:@"source"]];
}

1 Comment

-1 for SBJSON. If you're developing for iOS 5+, use built-in NSJSONSerialization. If not, use JSONKit... it's smaller and faster.

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.