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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T19:27:32+00:00 2026-06-16T19:27:32+00:00

I am using Restkit Version 0.2 to map JSON results to Objective-C Objects. The

  • 0

I am using Restkit Version 0.2 to map JSON results to Objective-C Objects. The JSON received looks like this:

{
"result": {
    "errorCode": 0,
    "errorMsg": "ok",
    "data": {
        "orderitems": [
            {
                "id": "46",
                "o_order_id": "15",
                "p_product_id": "7",
                "t_event_id": "1",
                "quantity": "1",
                "price": "4.5",
                "name": "Name1",
                "unit": "something1",
                "image": "images/7.png"
            },
            {
                "id": "47",
                "o_order_id": "15",
                "p_product_id": "10",
                "t_event_id": "1",
                "quantity": "1",
                "price": "3.99",
                "name": "Name2",
                "unit": "something2",
                "image": "images/10.png"
            }
        ]
    }
}
}

I defined the following mapping:

RKObjectMapping *oiMapping = [RKObjectMapping mappingForClass:[OrderItem class]];
[oiMapping mapKeyPathsToAttributes:@"p_product_id", @"productID", @"name", @"name",  @"t_event_id", @"eventID",  @"quantity", @"quantity",  nil];
[objectManager.mappingProvider setMapping:oiMapping forKeyPath:@"result.data.orderitems"];

RKObjectMapping *takeOrderResultMapping = [RKObjectMapping mappingForClass:[TakeOrderResult class]];
[takeOrderResultMapping mapKeyPathsToAttributes:@"errorCode", @"errorCode", @"errorMsg", @"errorMessage", nil];
[takeOrderResultMapping mapRelationship:@"orderitems" withMapping:oiMapping];

[objectManager.mappingProvider setMapping:takeOrderResultMapping forKeyPath:@"result"];
takeOrderResultMapping.rootKeyPath = @"result";
[[RKObjectManager sharedManager].mappingProvider setErrorMapping:takeOrderResultMapping]; 

And finally, the TakeOrderResult class is defined like this:

@interface TakeOrderResult : NSObject
@property (strong, nonatomic) NSNumber *errorCode;
@property (strong, nonatomic) NSString *errorMessage;
@property (strong, nonatomic) NSSet *orderitems;
@end

This more or less works – however, what Restkit returns is the an array of 3 Objects. The first object is an instance of TakeOrderResult with an empty set “orderitems”. The next two objects are instances of OrderItems.

It would be great if somebody could help me and point out why I don’t get 1 object, i.e. an instance of TakeOrderResult where “orderitems” is a set of two objects / two OrderItems.

  • 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-16T19:27:33+00:00Added an answer on June 16, 2026 at 7:27 pm

    Your mapping is slightly off.
    The reason you’re getting 3 objects is you’re adding both mappings to the mapping provider.
    The reason the “orderitems” is an empty set is because it doesn’t know how to find the orderitems.

    I have no idea if it works, but i’d try the following.
    Don’t add your oiMapping to the mapping provider.
    And instead of:

    [takeOrderResultMapping mapRelationship:@”orderitems” withMapping:oiMapping];

    try:

    [takeOrderResultMapping addRelationshipMappingWithSourceKeyPath:@”data.orderitems” mapping:oiMapping];

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

Sidebar

Related Questions

Using RestKit 0.10.1, I have objects served similar to this json format: {objects: [
Im using Restkit OM2 to take in a json and map to objects on
i am using coredata and restkit to map data. here is the json response
I am trying to map and store a response json data using restkit object
I am using RestKit 0.9.4. I would like to post a JSON that has
I'm using RestKit to load a gzipped JSON with RKRequest: RKRequest* request = [[RKClient
I am using RestKit, GData and Facebook API. All of them has a JSON
I am using a iOS library called Restkit, which automatically maps remote objects to
I need to send a JSON request to a REST service. I'm using Restkit
I'm using RestKit version 0.2 and I'm seeing it block the UI (meaning, the

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.