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 8208323
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T09:18:03+00:00 2026-06-07T09:18:03+00:00

I follow this link https://github.com/RestKit/RestKit/wiki/Posting-NSDictionary-as-JSON to create the json post, and get back json

  • 0

I follow this link https://github.com/RestKit/RestKit/wiki/Posting-NSDictionary-as-JSON to create the json post, and get back json response from server. How could I continue process the json response to a list of objects?

- (void)sendAsJSON:(NSDictionary*)dictionary {

    RKClient *client = [RKClient clientWithBaseURL:@"http://restkit.org"];        

    // create a JSON string from your NSDictionary 
    id<RKParser> parser = [[RKParserRegistry sharedRegistry] parserForMIMEType:RKMIMETypeJSON];
    NSError *error = nil;
    NSString *json = [parser stringFromObject:dictionary error:&error];

    // send your data
    if (!error)
        [[RKClient sharedClient] post:@"/some/path" params:[RKRequestSerialization serializationWithData:[json dataUsingEncoding:NSUTF8StringEncoding] MIMEType:RKMIMETypeJSON] delegate:self];

}


- (void)request:(RKRequest *)request didLoadResponse:(RKResponse *)response
{
    NSLog(@"after posting to server, %@", [response bodyAsString]);
}

EDIT1: this is the Json I want to POST to server.

{
    "memberId": "1000000",
    "countryCode": "US",
    "contacts": [
        {
            "phoneNumber": "+12233333333",
            "memberId": "2222",
            "contactId": "123456",
            "name": "john"
        },
        {
            "phoneNumber": "+12244444444",
            "memberId": "3333",
            "contactId": "123457",
            "name": "mary"
        }
    ]
}

EDIT2: Someone actually resolved this in another thread.
https://stackoverflow.com/a/7726829/772481

  • 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-07T09:18:05+00:00Added an answer on June 7, 2026 at 9:18 am

    Use RKObjectManger instead of RKClient to do the POST. You can then load the response into objects when this method is called:

    - (void)objectLoader:(RKObjectLoader*)objectLoader didLoadObjects:(NSArray*)objects
    

    EDIT (given JSON to send to server):

    Instead of creating the JSON the way that you’re currently doing it, you can create custom model classes.

    First, you can create a model class for your top level object (assuming it’s called User).

    User Header

    //  User.h
    
    #import <Foundation/Foundation.h>
    
    @interface User : NSObject
    
    @property (nonatomic) int memberId;
    @property (nonatomic, copy) NSString *countryCode;
    @property (nonatomic, strong) NSArray *contacts;
    
    @end
    

    User Implementation

    //  User.m
    
    #import "User.h"
    
    @implementation User
    
    @synthesize memberId;
    @synthesize countryCode;
    @synthesize contacts;
    
    @end
    

    Then, you can create a model class called Contact.

    Contact Header

    //  Contact.h
    
    #import <Foundation/Foundation.h>
    
    @interface Contact : NSObject
    
    @property (nonatomic, strong) NSString *phoneNumber;
    @property (nonatomic) int memberId;
    @property (nonatomic) int contactId;
    @property (nonatomic, strong) NSString *name;
    
    @end
    

    Contact Implementation

    //  Contact.m
    
    #import "Contact.h"
    
    @implementation Contact
    
    @synthesize phoneNumber;
    @synthesize memberId;
    @synthesize contactId;
    @synthesize name;
    
    @end
    

    You can use these classes as so:

    Contact *john = [[Contact alloc] init];
    john.phoneNumber = @"+12233333333";
    john.memberId = 2222;
    john.contactId = 123456;
    john.name = @"john";
    
    Contact *mary = [[Contact alloc] init];
    mary.phoneNumber = @"+12244444444";
    mary.memberId = 3333;
    mary.contactId = 123457;
    mary.name = @"mary";
    
    User *user = [[User alloc] init];
    user.memberId = 1000000;
    user.countryCode = @"US";
    user.contacts = [NSArray arrayWithObjects:john, mary, nil];
    
    RKObjectMapping *contactsMapping = [RKObjectMapping mappingForClass:[Contact class]];
    [contactsMapping mapKeyPath:@"phoneNumber" toAttribute:@"phoneNumber"];
    [contactsMapping mapKeyPath:@"memberId" toAttribute:@"memberId"];
    [contactsMapping mapKeyPath:@"contactId" toAttribute:@"contactId"];
    [contactsMapping mapKeyPath:@"name" toAttribute:@"name"];
    
    RKObjectMapping *objectMapping = [RKObjectMapping mappingForClass:[User class]];
    [objectMapping mapKeyPath:@"memberId" toAttribute:@"memberId"];
    [objectMapping mapKeyPath:@"countryCode" toAttribute:@"countryCode"];
    [objectMapping mapKeyPath:@"contacts" toRelationship:@"contacts" withMapping:contactsMapping];
    
    //Then you set up a serialization mapping and object mapping and POST it
    
    //This method takes care of both the serialization and object mapping
    [[RKObjectManager sharedManager].mappingProvider registerMapping:objectMapping withRootKeyPath:@"user"]; 
    
    //POST it
    [[RKObjectManager sharedManager] postObject:user delegate:self];
    

    I would need to know what kind of JSON response you’re expecting before I can show you how to do the serialization mapping and the POST.

    EDIT (given JSON returned from server):

    To set the serialization mapping and object mapping and POST it, you’ll need to set up the resource path (I do it when I launch my app):

    RKObjectRouter *router = [RKObjectManager sharedManager].router;
    [router routeClass:[User class] toResourcePath:@"/users" forMethod:RKRequestMethodPOST];
    

    Your resource path may be something other than “/users”.

    Take a look at the code under the comment //Then you set up a serialization mapping and object mapping and POST it, where I have added the serialization mapping, object mapping, and POSTing.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I tried to follow https://github.com/plataformatec/devise/wiki/OmniAuth:-Overview , but somehow when I look at the generated
Ie., follow this link: http://googleblog.blogspot.com/2012/04/toward-simpler-more-beautiful-google.html Notice, you'll see some spinning gears, and then the
I'm trying to do HEAD requests to follow 302 links, however this link: http://news.google.com/news/url?sa=t&fd=R&usg=AFQjCNGrJk-F7Dmshmtze2yhifxRsv8sRg&url=http://www.mtv.com/news/articles/1647243/20100907/story.jhtml
I´m trying to follow the step by step guide on this page: https://developers.google.com/picasa-web/docs/2.0/developers_guide_java?hl=nl-NL So,
If you follow this link to one of the pages on my site and
Just a follow up question to this one here => link Is it possible
This is follow up post where I'm having a problem where my php code
I follow this instruction to add bouncycastle: http://www.bouncycastle.org/wiki/display/JA1/Provider+Installation but I have still one problem.
I follow this tutorial to integrated facebook : http://25labs.com/tutorial-integrate-facebook-connect-to-your-website-using-php-sdk-v-3-x-x-which-uses-graph-api/ The problem is that when
I follow this rule but some of my colleagues disagree with it and argue

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.