如何使我的AFNetworking“ responseObject”我收到我可以解析的NSDictionary? [英] How do I make my AFNetworking "responseObject" that I receive a NSDictionary I can parse?

查看:170
本文介绍了如何使我的AFNetworking“ responseObject”我收到我可以解析的NSDictionary?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我通过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 7a2c7244 ... p>

<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?

推荐答案

这就是我的处理方法。.

This is how I do it..

- (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?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆