【发布时间】: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