2013-04-25 75 views
0

如何将Json filenames转换为NSArray?收到AFNetworking Json阵列

JSON:

(
     { 
     filename = "3801a77e22c2b552b4fef67b8454b727b291fd23.jpg"; 
    }, 
     { 
     filename = "c0839e7e8ba1ab53c3ff1faf3e261b84ec702a5f.jpg"; 
    } 
) 

申报到.H:

@property (nonatomic, retain) NSMutableArray *images; 

代码为.M:

NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"%@/initialimages", SERVER_APIURL]]; 
AFHTTPClient *httpClient = [[AFHTTPClient alloc] initWithBaseURL:url]; 
NSMutableURLRequest *request = [httpClient requestWithMethod:@"GET" path:nil parameters:nil]; 
[request setTimeoutInterval:15]; 

AFJSONRequestOperation *operation = [AFJSONRequestOperation JSONRequestOperationWithRequest:request success:^(NSURLRequest *request, NSHTTPURLResponse *response, id JSON) { 

    for (NSDictionary *dict in JSON) { 
     [_images addObject:[dict objectForKey:@"filename"]]; 
     NSLog(@"%@", _images); 
    } 

} failure:nil]; 
[operation start]; 

输出继电器:

2013-04-25 18:44:13.876 SP[6989:907] (null) 
2013-04-25 18:44:13.877 SP[6989:907] (null) 

回答

2

_images初始化在哪里?它看起来像是nil

您需要:

- (id) init 
{ 
    self = [super init]; 
    if (self) 
    { 
    _images = [NSMutableArray array]; 
    } 
    return self; 
} 
+0

行动,我忘了初始化'_images'。谢谢! – 2013-04-25 21:58:55