Objective C + Reskit – How do I wrap my dictionary with a key to avoid formatting problems?

I’m trying to wrap my HTTP POST request with a key. In other words, I want to turn this:


into this:

  • Rails 4 Error with every command “`load': no implicit conversion of nil into String” (Mac OS X 10.9)
  • omniauth for rails and ios authentication
  • Rails Devise OmniAuth Facebook Login from iOS
  • How to install json gem - Failed to build gem native extension(mac 10.10)
  • Manual Install of Xcode command line tools not working
  • Initialize Core Data With Default Data
  • {
    "dish" => 

    I tried using the ‘rootKeyPath’ method in RestKit:

    serializationMapping.rootKeyPath = @"dish";    

    But that gave me this weirdly formatted string :

        \n \"category_id\" = 1; 
        \n \"food_name_token\" = Pizza;
        \n id = 1;

    It uses equal signs and semicolons instead of arrows and commas, and adds in all these linebreaks and escape backslashes.

    Any idea why? And any suggestions on what I can do instead?

    P.S. I’m using a Rails backend

    3 Solutions Collect From Internet About “Objective C + Reskit – How do I wrap my dictionary with a key to avoid formatting problems?”

    NSDictionary *rootDictionary = [NSDictionary dictionaryWithObject:childDict forKey:@"dish"];

    This should solve it.

    I found out with Restkit I can wrap attributes using brackets:

        [dishMapping mayKeyPath:@"dish[food_name_token]" toAttribute:@"placeToken"];

    And this gives me a normal output without the weird formatting.

    Add the items into an NSArray, and then add the array into the NSDictionary, like this:

    NSDictionary *item = [NSDictionary dictionaryWithObjectsAndKeys:[NSArray arrayWithObject:results], @"Parent",nil];
    NSLog(@"NSDicitonary %@",item);
    NSLog(@"Child values %@",[item valueForKey:@"Parent"]);