KingPolygon
KingPolygon

Reputation: 4755

iOS: Twitter Stream API Returning Null For Expanded_URL even though Path is Correct?

This is json that's being returned:

{
    hashtags =     (
    );
    symbols =     (
    );
    urls =     (
                {
            "display_url" = "oust.com";
            "expanded_url" = "http://oust.com";
            indices =             (
                11,
                33
            );
            url = "http://t.co/NY8wYCI9Bc";
        }
    );
    "user_mentions" =     (
    );
}

I tried the following: [JSON valueForKey:@"urls[0]/url"]; but I keep getting (null). Any suggestions? Thank you all!

Upvotes: 0

Views: 84

Answers (2)

Ayhan Dorman
Ayhan Dorman

Reputation: 102

You can retrieve the url parameter from the json string returned by Twitter as follows:

NSString *url = [JSON[@"entities"][@"url"][@"urls"] valueForKey:@"url"];

Upvotes: 0

jrturton
jrturton

Reputation: 119242

That's not how valueForKey works. You're confusing it with literal accessors.

In your case, you'd need:

json[@"urls"][0][@"url"]

Assuming json is the root dictionary of your JSON response.

Upvotes: 1

Related Questions