我知道我的请求格式正确,但我从 Web 服务获得的响应不是 NSDictionary。
- 为什么它不是 NSDictionary?
如何判断“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"}]}