Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7838077
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T14:58:19+00:00 2026-06-02T14:58:19+00:00

I am using RestKit 0.9.4. I would like to post a JSON that has

  • 0

I am using RestKit 0.9.4. I would like to post a JSON that has a key that needs to be populated from an object’s attribute.
The JSON is as follows:

{
    "types":[ {
        "1" : "value1"
     },
     {  
         "7" : "value2"
     } ]
} 

I have an object with 2 NSString data members named keytype and value respectively .
keytype is the variable that has the values that appear for the key in the nested json above ( “1”, “7” etc above ). mapKeyOfNestedDictionaryToAttribute will probably not work here because the dynamic attribute( to be used as key) is at the inner most level..
Can this be posted using RestKit?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T14:58:21+00:00Added an answer on June 2, 2026 at 2:58 pm

    Here’s how you make that structure in an NSDictionary, and then post it as JSON using RestKit. Also, the response then maps to a model.

    // make the inner dictionaries (probably would use a for loop for this
    NSDictionary *dict1 = [[NSDictionary alloc] initWithObjectsAndKeys:@"value1", @"1", nil];
    NSDictionary *dict7 = [[NSDictionary alloc] initWithObjectsAndKeys:@"value2", @"7", nil];
    // put them in an array
    NSArray *types = [[NSArray alloc] initWithObjects:dict1, dict7, nil];
    // now put the array in a dictionary
    NSDictionary *finalDict = [[NSDictionary alloc] initWithObjectsAndKeys:types, @"types", nil];
    
    // create a JSON string from your NSDictionary
    NSError *error; 
    NSData *jsonData = [NSJSONSerialization dataWithJSONObject:finalDict 
                                                       options:NSJSONWritingPrettyPrinted // Pass 0 if you don't care about the readability of the generated string
                                                         error:&error];
    NSString *jsonString = [[NSString alloc] init];
    if (!jsonData) {
        NSLog(@"Got an error: %@", error);
    } else {
        jsonString = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
    }
    
    // make the post using the objectManager if you want to map the response to a model
    RKObjectManager* objectManager = [RKObjectManager sharedManager];  
    [objectManager loadObjectsAtResourcePath:@"/api/" delegate:self block:^(RKObjectLoader* loader) {
        loader.serializationMIMEType = RKMIMETypeJSON; // We want to send this request as JSON
        loader.objectMapping = [objectManager.mappingProvider objectMappingForClass:[Plan class]];
        loader.resourcePath = @"/api/";
        loader.method = RKRequestMethodPOST;
        loader.params = [RKRequestSerialization serializationWithData:[jsonString dataUsingEncoding:NSUTF8StringEncoding] MIMEType:RKMIMETypeJSON];
    }];
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using RestKit, GData and Facebook API. All of them has a JSON
I am using restkit to post the create action to my rails application from
I am using RESTKIT to map the JSON returned from server. The JSON result
When I try to post an object using RestKit I get the following error.
I'm using RestKit to develop a RESTful application. I have a wrapper object that
I'm using RestKit to load a gzipped JSON with RKRequest: RKRequest* request = [[RKClient
Using a restful resource in Rails, I would like to be able to insert
Using Flex 3, I would like to take an image snapshot such as this:
I'm using RestKit to grab objects from my RoR service and using CoreData to
I'm using the RestKit iOS package to allow a user to pull info from

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.