Reputation: 2600
How can I transfer Json filenames
to NSArray
?
JSON Received:
(
{
filename = "3801a77e22c2b552b4fef67b8454b727b291fd23.jpg";
},
{
filename = "c0839e7e8ba1ab53c3ff1faf3e261b84ec702a5f.jpg";
}
)
Declared into .h:
@property (nonatomic, retain) NSMutableArray *images;
Code into .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];
Ouput:
2013-04-25 18:44:13.876 SP[6989:907] (null)
2013-04-25 18:44:13.877 SP[6989:907] (null)
Upvotes: 0
Views: 956
Reputation: 70135
Where is _images
initialized? It looks like it is nil
.
You need:
- (id) init
{
self = [super init];
if (self)
{
_images = [NSMutableArray array];
}
return self;
}
Upvotes: 2