Note that there are some explanatory texts on larger screens.

plurals
  1. POMapping a JSON response to an object using RestKit and Objective-C
    primarykey
    data
    text
    <p>I am relatively new to Objective-C and am attempting to use RestKit to receive a JSON response from a web service. I have successfully received the data back to my application, which looks like this viewing the response:</p> <pre><code>{id:"1","Translation":"Test"} </code></pre> <p>I would like to map this translation to my "Translation" object in my application, but have tried a few different ways but am not sure how to achieve this.</p> <p>So my questions are:</p> <ol> <li>How can I map this response to my Translation object</li> <li>Am I doing this correctly, creating a method to complete this call outwit my view controller?</li> </ol> <h1>My Translation Object</h1> <pre><code>@implementation Translation @synthesize identifier = _identifier; @synthesize translation = _translation; - (NSDictionary*)elementToPropertyMappings { return [NSDictionary dictionaryWithKeysAndObjects: @"id", @"identifier", @"translation", @"translation", nil]; } @end </code></pre> <h1>My Translate Method</h1> <pre><code>- (NSString *)performTranslation:(NSString *)translation { NSString *data = [[NSString alloc] initWithFormat:@"{\"SourceId\": \"%@\",\"RegionTag\": \"%@\",\"InputString\": \"%@\"}", @"1", @"Glasgow", translation]; NSString *post = data; RKRequest *MyRequest = [[RKRequest alloc] initWithURL:[[NSURL alloc] initWithString:@"http://my.url.com/Translation/Translate"]]; MyRequest.method = RKRequestMethodPOST; MyRequest.HTTPBodyString = post; MyRequest.additionalHTTPHeaders = [[NSDictionary alloc] initWithObjectsAndKeys:@"application/json", @"Content-Type", @"application/json", @"Accept", nil]; [MyRequest send]; RKResponse *Response = [MyRequest sendSynchronously]; return Response.bodyAsString; &lt;--- looking to map this to translation object here } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload