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

  • Home
  • SEARCH
  • 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 6639117
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T23:30:59+00:00 2026-05-25T23:30:59+00:00

There are two JSON format that i came across: Format A: [ {topic: {category:testCategory,created_at:2011-09-27T05:41:42Z,

  • 0

There are two JSON format that i came across:

Format A:

[
  {"topic":
    {"category":"testCategory","created_at":"2011-09-27T05:41:42Z",
     "size":5,"title":"testTitle2", "id":1,
     "posts":[
               {"number":1,"created_at":"2011-09-27T05:41:42Z",
                "text":"text2","id":1,"topic_id":1},
               {"number":0,"created_at":"2011-09-27T05:41:42Z",
                "text":"sentence1","id":2,"story_id":1}
             ]
     }
  }
]

Format B:

[
    {"category":"testCategory","created_at":"2011-09-27T05:41:42Z",
     "size":5,"title":"testTitle2", "id":1,
     "posts":[
               {"number":1,"created_at":"2011-09-27T05:41:42Z",
                "text":"text2","id":1,"topic_id":1},
               {"number":0,"created_at":"2011-09-27T05:41:42Z",
                "text":"sentence1","id":2,"story_id":1}
             ]
     }
]

When my restKit client gets format B she is pleased but when she gets format A i get the following error:

 ... Could not find an object mapping for keyPath: '' ...

My restKit configurations is at the bottom.

So i fixed it by making my rails 3.1 server send her a format B JSON.

But now, restKit sends the server a format A JSON and he is stump as he should be.

Why does restKit won’t receive format A but sends formats A?
Is there a way to make restKit send a format B JSON?
Or, maybe is there a way to make rails send format B and receive format A?

my restKit configurations:

-(void)initRestKit{
RKObjectManager* objectManager = [RKObjectManager objectManagerWithBaseURL:@"http://localhost:3000/"];

objectManager.objectStore = [RKManagedObjectStore objectStoreWithStoreFilename:@"WTF.sqlite"];

// Setup our object mappings
RKManagedObjectMapping* topicMapping = [RKManagedObjectMapping mappingForClass:[Topic class]];
storyMapping.primaryKeyAttribute = @"topicID";
storyMapping.setDefaultValueForMissingAttributes = YES;
[storyMapping mapKeyPathsToAttributes:
 @"id", @"topicID",
 ....
 @"created_at", @"dateCreated", nil];

RKManagedObjectMapping* postMapping = [RKManagedObjectMapping mappingForClass:[Post class]];
sentencesMapping.primaryKeyAttribute = @"postID";
[sentencesMapping mapKeyPathsToAttributes:
 @"id", @"postID",
 ...
 @"text", @"text" , nil];

//setup relationships
[storyMapping mapRelationship:@"posts" withMapping:postMapping];//topic -> (posts) -> post

// Register our mappings with the provider
[objectManager.mappingProvider setMapping:topicMapping forKeyPath:@"topic"];
[objectManager.mappingProvider setMapping:postMapping forKeyPath:@"post"];

// Set Up Router
[objectManager.router routeClass:[Topic class] toResourcePath:@"/topics.json" forMethod:RKRequestMethodPOST];
[objectManager.router routeClass:[Topic class] toResourcePath:@"/topics/(topicID).json"];
[objectManager.router routeClass:[Post class] toResourcePath:@"/topics/(topic.topicID)/posts.json" forMethod:RKRequestMethodPOST];
[objectManager.router routeClass:[Post class] toResourcePath:@"/topics/(topic.topicID)/(post.postID).json"];    
}

-(void)sendTopic{
    RKObjectManager *manager =[RKObjectManager sharedManager];
    [manager postObject:self.topic delegate:nil block:^(RKObjectLoader *loader) { 
        RKObjectMapping* sendTopicMapping = [RKManagedObjectMapping mappingForClass:[Topic class]];
        [sendTopicMapping mapKeyPathsToAttributes:
         @"id", @"topicID",
         ....
         @"title", @"title", nil];

        RKManagedObjectMapping* postPostMapping = [RKManagedObjectMapping mappingForClass:[Post class]];
        [postPostMapping mapKeyPathsToAttributes:
         @"id", @"postID",
          ....
         @"text", @"text" , nil];

        [sendTopicMapping mapRelationship:@"posts" withMapping:postPostMapping];
        [manager.mappingProvider setMapping:sendTopicMapping forKeyPath:@"topic"];

        loader.serializationMapping = [sendTopicMapping inverseMapping];
    }];
 }
  • 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-05-25T23:31:00+00:00Added an answer on May 25, 2026 at 11:31 pm

    I solved it if anyone is interested:

    in rails i changed the modle so it will send the restKit client nested json(Format A) like this:

    class Topic < ActiveRecord::Base
      has_many :posts
      accepts_nested_attributes_for :posts
      self.include_root_in_json = true 
    end
    

    I made the post method attributes nested like this:

    -(void)sendTopic{
        RKObjectManager *manager =[RKObjectManager sharedManager];
        [manager postObject:self.topic delegate:nil block:^(RKObjectLoader *loader) { 
        RKObjectMapping* sendTopicMapping = [RKManagedObjectMapping mappingForClass:[Topic class]];
        [sendTopicMapping mapKeyPathsToAttributes:
         @"topic[id]", @"topicID",
         ....
         @"topic[title]", @"title", nil];
    
        RKManagedObjectMapping* postPostMapping = [RKManagedObjectMapping mappingForClass:[Post class]];
        [postPostMapping mapKeyPathsToAttributes:
         @"post[id]", @"postID",
          ....
         @"post[text]", @"text" , nil];
    
        [sendTopicMapping mapRelationship:@"posts" withMapping:postPostMapping];
        [manager.mappingProvider setMapping:sendTopicMapping forKeyPath:@"topic"];
    
        loader.serializationMapping = [sendTopicMapping inverseMapping];
        }];
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

To start, I know there are two kinds of JSON serialization currently built into
I need a library to handle JSON objects in Ruby. There are two gems
I have read a document that they say: In java there two types of
I got two questions, but I think that there linked in someways. I made
We have two systems: external and internal, which are sharing information in JSON format
There are two JSON var (JSON.parse'd already) var acc http://pastebin.com/7DyfFzTx var sit http://pastebin.com/vnZiVaDx My
How to return values from Webmethod to the client in JSON format? There are
There are two weird operators in C#: the true operator the false operator If
There are two popular closure styles in javascript. The first I call anonymous constructor
There are two popular naming conventions: vc90/win64/debug/foo.dll foo-vc90-win64-debug.dll Please discuss the problems/benefits associated with

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.