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)
行動,我忘了初始化'_images'。謝謝! – 2013-04-25 21:58:55