0

如何将 Json 转移filenamesNSArray?

收到的 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)
4

1 回答 1

2

在哪里_images初始化?看起来是这样nil

你需要:

- (id) init
{
   self = [super init];
   if (self)
   {
     _images = [NSMutableArray array];
   }
   return self;
}
于 2013-04-25T21:55:40.743 回答