gpt4 book ai didi

ios - AFNetworking (iOS) - 响应不是 NSDictionary

转载 作者:行者123 更新时间:2023-11-28 18:13:05 25 4
gpt4 key购买 nike

我知道我的请求格式正确,但我从网络服务获得的响应不是 NSDictionary。

  1. 为什么它不是 NSDictionary?
  2. 如何判断“responseObject”是哪种对象?

    AFHTTPRequestOperation *operation = [[AFParseAPIClient sharedClient]  HTTPRequestOperationWithRequest:request success:^(AFHTTPRequestOperation *operation, id responseObject) {
    if ([responseObject isKindOfClass:[NSDictionary class]]) {
    NSLog(@"Response for %@: %@", className, responseObject);
    [self writeJSONResponse:responseObject toDiskForClassWithName:className];
    }else{
    //NSLog(@"Response NOT NSDictionary: %@", [responseObject class]);
    NSString *str = [[NSString alloc] initWithData:responseObject encoding:NSUTF8StringEncoding];
    NSLog(@"str: %@", str);
    }
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
    NSLog(@"Request for class %@ failed with error: %@", className, error);
    }];

这是我得到的:

//Response NOT NSDictionary: <7b227265 73756c74 73223a5b 7b22636f ...>

编辑:这是我得到的结果:

str: {"results":[{"desc":"My description.","device_iPad":true,"device_iPhone":true,"createdAt":"2012-09-05T18:36:11.431Z","updatedAt":"2012-09-05T22:00:52.199Z"}]}

最佳答案

只需在创建操作后添加这行代码

operation.responseSerializer = [AFJSONResponseSerializer 序列化器];

关于ios - AFNetworking (iOS) - 响应不是 NSDictionary,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12290207/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com