Iphone 如何从这个哈希中获取 ID 和所有者到 NString 中。
{ "photos": { "page": 1, "pages": 26, "perpage": 10, "total": "259",
"photo": [
{ "id": "8493465829", "owner": "77009896@N08", "secret": "e0a8381648", "server": "8367", "farm": 9, "title": "IMG_9444", "ispublic": 1, "isfriend": 0, "isfamily": 0 },
{ "id": "8494565062", "owner": "77009896@N08", "secret": "6aaa0f41b9", "server": "8372", "farm": 9, "title": "IMG_9443", "ispublic": 1, "isfriend": 0, "isfamily": 0 },
{ "id": "8493492761", "owner": "77009896@N08", "secret": "30f4da89b4", "server": "8523", "farm": 9, "title": "IMG_9488", "ispublic": 1, "isfriend": 0, "isfamily": 0 },
{ "id": "8493492007", "owner": "77009896@N08", "secret": "95c0f2215e", "server": "8529", "farm": 9, "title": "IMG_9487", "ispublic": 1, "isfriend": 0, "isfamily": 0 },
{ "id": "8493471375", "owner": "77009896@N08", "secret": "812fddc8cd", "server": "8516", "farm": 9, "title": "IMG_9453", "ispublic": 1, "isfriend": 0, "isfamily": 0 },
{ "id": "8493463059", "owner": "77009896@N08", "secret": "7eedfd6b7c", "server": "8389", "farm": 9, "title": "IMG_9440", "ispublic": 1, "isfriend": 0, "isfamily": 0 },
{ "id": "8494572044", "owner": "77009896@N08", "secret": "e4d514021d", "server": "8087", "farm": 9, "title": "IMG_9454", "ispublic": 1, "isfriend": 0, "isfamily": 0 },
{ "id": "8493462429", "owner": "77009896@N08", "secret": "43822f14a5", "server": "8526", "farm": 9, "title": "IMG_9439", "ispublic": 1, "isfriend": 0, "isfamily": 0 },
{ "id": "8493489419", "owner": "77009896@N08", "secret": "8b50906ebe", "server": "8515", "farm": 9, "title": "IMG_9480", "ispublic": 1, "isfriend": 0, "isfamily": 0 },
{ "id": "8493488459", "owner": "77009896@N08", "secret": "7ec696b8d0", "server": "8242", "farm": 9, "title": "IMG_9479", "ispublic": 1, "isfriend": 0, "isfamily": 0 }
] }, "stat": "ok" }
这段代码给了我一个错误
NSDictionary *photos =[JSON objectForKey:@"photos"];
NSDictionary *picturesOfLocations = photos[@"photo"];
NSString *flickUserID = picturesOfLocations[@"id"];
// NSURL *url = [[NSURL alloc] initWithString:[picturesOfLocations objectForKey:@"photo"]];
//NSData *data = [NSData dataWithContentsOfURL:url];
// cell.imageView.image = [[UIImage alloc] initWithData:data];
NSLog(@"%@", flickUserID);
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFArray objectForKeyedSubscript:]: unrecognized selector sent to instance 0x7527430'
*** First throw call stack:
(0x1ce3012 0x1120e7e 0x1d6e4bd 0x1cd2bbc 0x1cd294e 0x24dd9 0x171f2 0x185b9 0x4a4753f 0x4a59014 0x4a497d5 0x1c89af5 0x1c88f44 0x1c88e1b 0x1c3d7e3 0x1c3d668 0x64ffc 0x244d 0x2375)
libc++abi.dylib: terminate called throwing an exception
尝试以下操作时出现同样的错误
NSURLRequest *request = [[NSURLRequest alloc] initWithURL:url];
AFJSONRequestOperation *operation = [AFJSONRequestOperation JSONRequestOperationWithRequest:request success:^(NSURLRequest *request, NSHTTPURLResponse *response, id JSON) {
NSDictionary* dict = [NSJSONSerialization JSONObjectWithData:JSON options:kNilOptions error:nil];
NSString* stringPhoho = [[[[dict valueForKey:@"photos"] valueForKey:@"photo"] objectForKey:0] valueForKey:@"owner"];
NSLog(@"%@",stringPhoho);