本文介绍了如何使我的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):

如果我这样做:

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

09-19 00:10