Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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:

{
"category_id"=>"1", 
"food_name_token"=>"Pizza", 
 "id"=>"1"
}

into this:

{
"dish" => 
    {
    "category_id"=>"1", 
    "food_name_token"=>"Pizza", 
    "id"=>"1"
    }
}

I tried using the 'rootKeyPath' method in RestKit:

serializationMapping.rootKeyPath = @"dish";    

But that gave me this weirdly formatted string :

{
"dish"=>
    "{
    \n \"category_id\" = 1; 
    \n \"food_name_token\" = Pizza;
    \n id = 1;
    \n}
"}

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

like image 348
Jonathan Chiu Avatar asked Oct 10 '22 10:10

Jonathan Chiu


1 Answers

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

This should solve it.

like image 146
Alex Zielenski Avatar answered Oct 18 '22 13:10

Alex Zielenski