2013-10-30 102 views
2

所以我仍然在学习iOS和JSON。iOS flickr搜索照片json返回零

所以我认为我已经理解了基础知识(显然是某种东西):也许它是一个编码问题。

#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"); 

因此,URL请求看起来不错,并且String会打印出完整的JSON对象。 但是我创建的JSON对象是NILL,也许这是一个编码问题。

有没有关于编码? (在非Twitter JSON页面上,这种方法奏效)。

+1

看起来像你有当您键入您的标题时,您的大写字母锁定键被激活,我已经将其修正为对眼睛更友好。 – Femaref

回答

2

我不知道试试这个,

更改URL格式,这在你的代码,并检查


[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]]; 


其中,SEARCHTERM串什么妳正在搜索

+0

谢谢你的工作。那么为什么它会像我以前一样在一起做所有事情时都像这样工作? – drlobo