问题描述
我对 AFNetworking 1.0 进行了此调用,该调用返回一个 responseObject
,其中包含来自我想要的 API 的数据:
I have this call with AFNetworking 1.0 that returns a responseObject
with the data from the API that I want:
[[AFDiffbotClient sharedClient] postPath:@"http://diffbot.com/api/batch" parameters:parameters success:^(AFHTTPRequestOperation *operation, id responseObject) {
但是,我不知道如何处理responseObject
.
However, I have no idea how to process responseObject
.
如果我检查 [responseObject class]
,我会得到 NSData
.
If I check [responseObject class]
I get NSData
.
如果我 NSLog(@"%@", responseObject)
我得到一堆数字(我假设的内存地址):
If I NSLog(@"%@", responseObject)
I get a bunch of numbers (memory addresses I assume):
< 5b0a7b22 68656164 65727322 3a5b7b22 6e616d65 223a6e75 6c6c2c22 76616c75 65223a22 48545450 2f312e31 20323030 204f4b22 7d2c7b22 6e616d65 223a2244 61746522 2c227661 ...
如果我这样做:
NSString *responseString = [[NSString alloc] initWithData:responseObject encoding:NSUTF8StringEncoding];
NSLog(@"%@", responseString);
我得到了我想要的输出!但是,它是一个NSString
.
I get the output that I want! But, it's an NSString
.
如果我这样做:
NSError *error;
NSDictionary *responseDictionary = [NSJSONSerialization JSONObjectWithData:responseObject options:kNilOptions error:&error];
NSLog(@"%@", responseDictionary);
我得到一个 NSDictionary
,但它缺少绝大多数响应(即:我没有得到 NSString
方法中包含的内容).
I get an NSDictionary
, but it's missing the vast majority of the response (i.e.: I don't get what's included with the NSString
method).
我应该如何处理这个对象?
How should I be processing this object?
推荐答案
我就是这样做的..
- (void) requestDataFinish:(NSData *)data withError:(NSError *)networkError
{
NSDictionary *responseData;
NSError *error = nil;
if (data != nil) {
responseData = [NSJSONSerialization JSONObjectWithData:data
options:NSJSONReadingMutableContainers
error:&error];
}
...
这篇关于如何让我的 AFNetworking “responseObject"我收到一个可以解析的 NSDictionary?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!