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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T21:24:35+00:00 2026-06-05T21:24:35+00:00

I’m new to iOS development and I’m having trouble making a simple Json POST

  • 0

I’m new to iOS development and I’m having trouble making a simple Json POST request.
I have a NSDictionary containing an user and password and I want to send those values as a Json to a server and get a response. I had that working without using restkit but I can’t figure out how to accomplish the same using RestKit and just can’t find a good example of what I want.

- (bool) login{

    NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
    [params setValue:self.email forKey:@"email"];
    [params setValue:self.password forKey:@"password"];    

    NSMutableDictionary* rpcData = [[NSMutableDictionary alloc] init];
    [rpcData setValue:@"2.0" forKey:@"jsonrpc"];
    [rpcData setValue:@"authenticate" forKey:@"method"];
    [rpcData setValue:@"" forKey:@"id"];
    [rpcData setValue:params forKey:@"params"];

    [[RKClient sharedClient] post:@"/api/rpc/" params:rpcData delegate:self];
    return nil;
}

The server is expecting a Json like this:

{
    jsonrpc : '2.0',
    method : 'authenticate', // method name goes here
    params : {  // params are method-specific
        email : 'test@test.com',
        password : 'secret'
    },
    id : 2  // The id can be anything, it will be sent back with the response
}

I understand that there is a Json parser include in RestKit but I can’t find any documentation on how to parse my rpcData dictionary, do I need to use an external library?.

Right now the communication with the server it’s ok, but I’m not sending what is expected. My dictionary is mapped in the way “key=value?key2=value2…”. This is very silly question but I’m stucked.

Update

By the time I wrote this, it worked but Restkit has been updated so I’m not sure if this will work, please check their documentation

Here is the solution to my problem, what I’m doing is ideal for working with RPC APIs when you need to call a service:

1.- First in your object you need to import Restkit and RKRequestSerialization, this is very important:

#import <RestKit/RestKit.h>
#import <RestKit/RKRequestSerialization.h>

@interface myObject : NSObject <RKRequestDelegate,RKObjectLoaderDelegate>

2.- Here is the login function sending the post:

- (void) login:(NSString *)username :(NSString *)password{

    RKClient *myClient = [RKClient sharedClient];
    NSMutableDictionary *rpcData = [[NSMutableDictionary alloc] init ];
    NSMutableDictionary *params = [[NSMutableDictionary alloc] init];

    //User and password params
    [params setObject:password forKey:@"password"];
    [params setObject:username forKey:@"email"];

    //The server ask me for this format, so I set it here:
    [rpcData setObject:@"2.0" forKey:@"jsonrpc"];
    [rpcData setObject:@"authenticate" forKey:@"method"];
    [rpcData setObject:@"" forKey:@"id"];
    [rpcData setObject:params forKey:@"params"];

    //Parsing rpcData to JSON! 
    id<RKParser> parser = [[RKParserRegistry sharedRegistry] parserForMIMEType:RKMIMETypeJSON];
    NSError *error = nil;
    NSString *json = [parser stringFromObject:rpcData error:&error];    

    //If no error we send the post, voila!
    if (!error){
        [[myClient post:@"/" params:[RKRequestSerialization serializationWithData:[json dataUsingEncoding:NSUTF8StringEncoding] MIMEType:RKMIMETypeJSON] delegate:self] send];
    }
}
  • 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-05T21:24:37+00:00Added an answer on June 5, 2026 at 9:24 pm

    I had the same problem, and this is what solved it for me. Note, in my scenario, I only wanted to access RKRequest.

    NSDictionarty *dict
    NSError *error; 
    NSData *jsonData = [NSJSONSerialization dataWithJSONObject:dict options:0 error:&error];
    
    if (!jsonData) 
    {
        NSAssert(FALSE, @"Unable to serialize JSON from NSDict to NSData"); 
    } 
    else 
    {
        NSString *jsonString = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
        request.params = [RKRequestSerialization serializationWithData:[jsonString dataUsingEncoding:NSUTF8StringEncoding] MIMEType:RKMIMETypeJSON];
    }
    

    The key for me was the ‘MIMEType:RKMIMETypeJSON’ in the last line. Since I only wanted to use RKRequest, this was how I needed to set the MIME type. Otherwise, I would use Paul Cezanne’s suggestion.

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

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm having trouble keeping the paragraph square between the quote marks. In firefox the
I'm making a simple page using Google Maps API 3. My first. One marker
I have a view passing on information from a database: def serve_article(request, id): served_article
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
I have a jquery bug and I've been looking for hours now, I can't
this is what i have right now Drawing an RSS feed into the php,
I want use html5's new tag to play a wav file (currently only supported

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.