【问题标题】:iOS flickr search photos json returning niliOS flickr 搜索照片 json 返回 nil
【发布时间】:2013-10-30 11:11:48
【问题描述】:

所以我还在学习 iOS 和 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 请求看起来不错,字符串打印出完整的 JSON 对象。 但是我创建的 JSON 对象是 NILL,可能是编码问题。

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

【问题讨论】:

  • 看起来您在输入标题时激活了大写锁定键,我已对其进行了更正,使其看起来更友好。

标签: ios json nsdictionary nsjsonserialization


【解决方案1】:

我不确定试试这个,

在您的代码中将 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]];


where,searchTerm string 你在搜索什么

【讨论】:

  • 感谢工作。那么,为什么它会像我以前那样将所有东西都放在一起呢?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2011-03-06
  • 2010-12-31
  • 1970-01-01
  • 2013-04-25
  • 1970-01-01
  • 1970-01-01
  • 2018-11-21
相关资源
最近更新 更多