I'm trying to call a RESTful web service with RESTKit 0.2
that returns only a string, but the RKResponseDescriptor
class forces me to use a mapping with its method responseDescriptorWithMapping
in order to be able to get the string value, I created the mapping and got the string value without any problems, but how can i get this string value without having to create the object mapping (i.e. creating an NSObject
subclass, creating a property for the string to be received, and creating a mapping dictionary between the returned JSON key and this property) ?
问问题
846 次
2 回答
2
您仍然可以使用 RestKit 来发出请求。有时这样做是有意义的,以防服务器返回错误,在这种情况下,有必要访问从服务器返回的原始数据。
[[RKObjectManager sharedManager] getObjectsAtPath:kLoginURL
parameters:params
success:^(RKObjectRequestOperation *operation, RKMappingResult *mappingResult) {
NSError *error;
NSDictionary* json = [NSJSONSerialization JSONObjectWithData:operation.HTTPRequestOperation.responseData options:NSJSONReadingMutableLeaves error:&error];
NSLog(@"msg: %@", [json objectForKey:@"msg"]);
}
failure:^(RKObjectRequestOperation *operation, NSError *error) {
}];
于 2015-02-23T17:15:26.887 回答
1
在这种情况下,不要使用 RestKit 来发出请求。RestKit 使用AFNetworking进行底层网络通信,因此如果您导入类,您也可以使用它。尝试直接使用AFHTTPRequestOperation
来发出请求。
于 2013-06-14T18:13:22.813 回答