這是我的代碼。AFNetworking 2.0 JSON解析
(void)performHttpRequestWithURL :(NSString *)urlString :(NSMutableArray *)resultArray completion:(void (^)(NSArray *results, NSError *error))completion
{
NSURL *myUrl = [NSURL URLWithString:urlString];
NSURLRequest *request = [[NSURLRequest alloc] initWithURL:myUrl cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:10];
AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc] initWithRequest:request];
[operation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject)
{
NSLog(@"請求完成");
NSArray *arr;
arr = [NSJSONSerialization JSONObjectWithData:operation.responseData options:NSJSONReadingAllowFragments error:NULL];
[resultArray addObjectsFromArray:arr];
if (completion) {
completion(resultArray, nil);
}
}failure:^(AFHTTPRequestOperation *operation, NSError *error){
NSLog(@"請求失敗: %@", error);
if (completion) {
completion(nil, error);
}
}];
[operation start];
}
我只能用蘋果JSON解析,我不知道如何使用AFNetworking JSON解析本身。 我沒有在AFNetworking 2.0.ask找到AFJsonrequestOperaton的求助,謝謝。
您是否閱讀過AFNetworking文檔? https://github.com/AFNetworking/AFNetworking#afhttprequestoperation – rckoenes
你的問題是什麼?我在這裏沒有看到問題。難道你找不到AFNetwork JSONRequest? –
嘿,我剛剛發佈和回答示例 –