Reputation: 4755
I'm trying to pull in the first url of a tweet using -objectForKey:
, and I was wondering how I can pull in the expanded url in 1 go.
Here's the json:
"entities":{
"hashtags":[
],
"symbols":[
],
"urls":[
{
"url":"http:\/\/t.co\/example",
"expanded_url":"http:\/\/example.com\/hi",
"display_url":"example.com\/hi",
"indices":[
46,
68
]
}
],
"user_mentions":[
]
},
This is what I tried: NSLog(@"URL FOUND: %@", [JSON objectForKey:@"entities/urls/expanded_url"]);
but I got (null
).
Upvotes: 0
Views: 236
Reputation: 876
"urls":[
{
"url":"http:\/\/t.co\/example",
"expanded_url":"http:\/\/example.com\/hi",
"display_url":"example.com\/hi",
"indices":[
46,
68
]
}
],
Here, value of urls
is an array, so you should use path like entities/urls[0]/expanded_url
Update:
I don't know which JSON decode library you use.
Take famous JSONKit
(https://github.com/johnezang/JSONKit) as an example:
NSString *str = @"{\"entities\":{\"urls\":[{\"url\":\"http://t.co/example\"}]}}";
NSDictionary *dict = [str objectFromJSONString];
NSLog(@"URL: %@",dict[@"entities"][@"urls"][0][@"url"]);
Upvotes: 0
Reputation: 3921
This code will be help for you
NSArray *urls = [[JSON objectForKey:@"entities"] objectForKey:@"urls"];
NSString *url = [[urls objectAtIndex:0] objectForKey:@"url"];
NSLog(@"%@",url);
Upvotes: 1