到目前为止,利用 AFNetworking 2.5 通过 last.fm API 来填充与热门轨道相关的艺术家的数组一直是一个挑战。这是我当前执行此操作的代码。
NSURL *url = [NSURL URLWithString:URLstring];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc]initWithRequest:request];
operation.responseSerializer = [AFJSONResponseSerializer serializer];
[operation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) {
NSDictionary *dict = (NSDictionary *)responseObject;
NSArray *allValues = [dict allValues];
NSLog(@"all values contained in array: %@", allValues);
NSLog(@"all values count: %lu", allValues.count);
计数返回 1。我想要一个填充有轨道的数组,并且每个索引值对应于一个轨道。目前,数组中仅填充第一个索引值。我还注意到打印回的 JSON 数据是 JSON 格式的,并且不像打印时出现的 NSArray 中的对象那样。
编辑:这是 input
最佳答案
使用KVC获取轨道数组:
NSArray* tracks = [dict valueForKeyPath:@"toptracks.track"]
或者类似的东西
关于ios - 使用 AFNetworking 2.5 将 JSON 序列化为 NSArray,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27284696/