我正在努力學習AFNetworking,所以寫了一個簡單的塊。我試圖從下面的網站url檢索&登錄json。AFNetworking JSON請求,既沒有成功也沒有錯誤塊調用
NSString *string =
@"http://transportapi.com/v3/uk/bus/stop/490012745J/live.json?api_key=6ee115459cbeccdb902b14d39b61330d&app_id=9deefeb1&group=route";
NSURL *url = [NSURL URLWithString:string];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc] initWithRequest:request];
operation.responseSerializer = [AFJSONResponseSerializer serializer];
[operation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject)
{
NSDictionary *mydict = (NSDictionary *)responseObject;
NSString *key;
for(key in mydict){
NSLog(@" key %@", key);
}
}
failure:^(AFHTTPRequestOperation *operation, NSError *error) {
NSLog(@"ERROR");
}];
但是無論是成功還是失敗塊都被調用。有人能指出我做錯了什麼嗎?
我猜你的操作被解除的操作,你應該保留它時,請求尚未完成 – oldman