JAHelia
JAHelia

Reputation: 7932

getting JSON data without object mapping using RestKit 0.2

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

Upvotes: 1

Views: 855

Answers (2)

plgrenier
plgrenier

Reputation: 293

You can still use RestKit to make the request. Sometimes it makes sense to do so in case server is returning an error for example, in which case it is necessary to access the raw data returned from server.

[[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) {
                                          }];

Upvotes: 2

Wain
Wain

Reputation: 119031

In this case, don't use RestKit to make the request. RestKit uses AFNetworking for the underlying network communications so if you import the classes you can use it too. Try directly using AFHTTPRequestOperation to make the request.

Upvotes: 1

Related Questions