この方法でAFHHTPClientを使用してサーバーからデータを要求すると:
[[NetworkHelper sharedHelper] postPath:path parameters:parameters] success:^(AFHTTPRequestOperation *operation, id responseObject) {
NSLog(@"%@", [operation class]);
NSLog(@"%@", [responseObject class]);
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
NSLog(@"%@", [error localizedDescription]);
}];
私はこれを得た:
2012-10-10 13:24:36.881 MyApp[4635:c07] AFHTTPRequestOperation
2012-10-10 13:24:36.881 MyApp[4635:c07] NSConcreteData
application/json
サーバーの応答で content-typeを強制しようとしましたが、まだAFHTTPRequestOperation
.
しかし、私がこれを使用する場合:
[[AFJSONRequestOperation JSONRequestOperationWithRequest:[NSURLRequest requestWithURL:myURL] success:^(NSURLRequest *request, NSURLResponse *response, id JSON) {
NSLog(@"%@", JSON);
} failure:^(NSURLRequest *request, NSURLResponse *response, NSError *error, id JSON) {
NSLog(@"%@", [error localizedDescription]);
}] start];
必要な JSON レスポンスを取得しました。
AFHTTPClient で JSON 応答を取得するにはどうすればよいですか?
アップデート:
クラスNSLog(@"%@",[self.response MIMEType]);
に- (BOOL)hasAcceptableContentType
メソッドを追加すると、受信しますAFHTTPRequestOperation
2012-10-11 09:48:25.052 MyApp[3339:3803] application/json
しかし、私はまだAFHTTPRequestOperation
クラスを取得します。