Question

So I am still learning about iOS and JSON.

So I thought I have understood the basics (clearly something): maybe its an encoding issue.

#define flickrGetURL [NSURL URLWithString:@"http://www.flickr.com/services/rest/?method=flickr.photos.search&tags=football&safe_search=1&per_page=20&format=json&api_key=YOURAPIREPLACESHERE"]

NSData* data = [NSData dataWithContentsOfURL:flickrGetURL];
NSError* error;
//this works
NSString *stringData = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
NSLog(@"Response data being called : %@", stringData);

NSDictionary* json = [NSJSONSerialization JSONObjectWithData:data options:0 error:&error];
if(json == nil)
{
    NSLog(@"NULL");
}else 
    NSLog(@" WORKED");

So the URL request looks good and the String prints out the full JSON object. However the JSON object that I create is NILL, maybe it's an encoding issue.

Is there something to do with encoding ?? (on a non-Twitter JSON page this approach worked).

Was it helpful?

Solution

I am not sure try this,

change the url format to this in your code and check


[NSURL URLWithString:[NSString stringWithFormat:@"http://api.flickr.com/services/rest/?method=flickr.photos.search&api_key=%@&text=%@&per_page=20&format=json&nojsoncallback=1",kFlickrAPIKey,searchTerm]];


where,searchTerm string what u are searching

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top