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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T13:29:15+00:00 2026-05-27T13:29:15+00:00

With the help of mja, I managed to successfully set up simple object mapping

  • 0

With the help of mja, I managed to successfully set up simple object mapping using RestKit and Objective-C. Please see my previous question here.

My next step was to attempt to deal with nested JSON in the same way.

My JSON looks like this, with the outer being a CandidatePhrase with some nested ‘Votes’:

{ "Id":33696,
"Phrase": "phrase",
"BadCount":0,
"Votes":[{"Id":447,"OriginalId":33696,"Votes":2,"Translation":"translation 1"},
{"Id":746,"OriginalId":33696,"Votes":1,"Translation":"translation 2"},
{"Id":747,"OriginalId":33696,"Votes":1,"Translation":"translation 3"}
]}

I created a relationship in my AppDelegate as follows:

[candidatePhraseMapping mapKeyPath:@"votes" toRelationship:@"vote" withMapping:voteMapping];

When I call make my request in my controller, I’m able to deal with the rest of the CandidatePhrase okay, but am not really sure how to map the nested ‘Vote’ objects into an array so I can use them in a TableView

(pseudo-code something like this…)

// Store the votes in an array
_votes = [[NSArray alloc] initWithObjects:myCandidatePhrase.votes, nil];

Here’s my CandidatePhrase Object

@interface CandidatePhrase : NSObject

@property (nonatomic, retain) NSNumber* ident;
@property (nonatomic, retain) NSNumber* badcount;
@property (nonatomic, retain) NSString* phrase;
@property (nonatomic, retain) NSArray* votes;

@end

and my Vote object

@interface Vote : NSObject

@property (nonatomic, retain) NSNumber* ident;
@property (nonatomic, retain) NSNumber* originalId;
@property (nonatomic, retain) NSNumber* votecount;
@property (nonatomic, retain) NSString* translation;

+ (id)voteWithTranslationId:(NSNumber *)ident translation:(NSString *)translation;

@end

Any help would be much appreciated.

EDIT

Below is my mapping code

// Votes Mapping

RKObjectMapping* voteMapping = [RKObjectMapping mappingForClass:[Vote class]];
[voteMapping mapKeyPath:@"Id" toAttribute:@"ident"];
[voteMapping mapKeyPath:@"OriginalId" toAttribute:@"originalId"];
[voteMapping mapKeyPath:@"Votes" toAttribute:@"votecount"];
[voteMapping mapKeyPath:@"Translation" toAttribute:@"translation"];

[[manager mappingProvider] addObjectMapping:voteMapping];

// Candidate Phrase Mapping
RKObjectMapping *candidatePhraseMapping = [RKObjectMapping mappingForClass:[CandidatePhrase class]];

[candidatePhraseMapping mapKeyPath:@"Id" toAttribute:@"ident"];
[candidatePhraseMapping mapKeyPath:@"Phrase" toAttribute:@"phrase"];
[candidatePhraseMapping mapKeyPath:@"BadCount" toAttribute:@"badcount"];

[candidatePhraseMapping mapKeyPath:@"Votes" toRelationship:@"votes" withMapping:voteMapping];

[[manager mappingProvider] addObjectMapping:candidatePhraseMapping];

For clarity also, here’s how I’m attempting to access the vote items on the controller

- (void)objectLoader:(RKObjectLoader*)objectLoader didLoadObject:(id)object 
{ 
    CandidatePhrase *myCandidatePhrase = (CandidatePhrase*)object;
    self.candidateText.text = myCandidatePhrase.phrase; <-- works fine

    _votes = [[NSArray alloc] initWithObjects:myCandidatePhrase.votes, nil];
    for (id o2 in _votes) { 
        //Vote *vote = o2; 
        NSLog(@"Item name: %@", o2); <-- sees object but crashes
    }

    NSLog(@"Votes: %@", myCandidatePhrase.votes); 
    _votes = [[NSArray alloc] initWithObjects:myCandidatePhrase.votes, nil];
     [_votesTableView reloadData];
 } 

and my table is binding with

Vote *vote = [_votes objectAtIndex:indexPath.row];
cell.textLabel.text = vote.translation;
  • 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-27T13:29:16+00:00Added an answer on May 27, 2026 at 1:29 pm

    You do not need to manually manage the nested NSArray. I believe the problem might be just a simple typo, as you map keyPath “votes”, but your json contain “Votes” with capital “V”.

    [candidatePhraseMapping mapKeyPath:@"Votes" toRelationship:@"votes" withMapping:voteMapping];
    

    If this doesn’t help feel free to leave a comment and update your question with voteMapping.

    Also, the contents of the didLoadObject can be simplified:

    //in .h file
    @property (nonatomic, retain) NSArray* votes;
    
    // in implementation
    @synthesize votes;
    
    ...
    - (void)objectLoader:(RKObjectLoader*)objectLoader didLoadObject:(id)object 
    { 
        CandidatePhrase *myCandidatePhrase = (CandidatePhrase*)object;
        self.candidateText.text = myCandidatePhrase.phrase;
        self.votes = myCandidatePhrase.votes;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am having trouble mapping a JSON response to objects using RestKit and Objective-C.
Help please :) I have set up a mutable array as follows - (void)viewDidLoad
Help please! my first program in objective c. Followed a tutorial word for word
Help me with building object model, please. I need abstract class Unit representing each
help me please with this simple E-sql query: var qStr = SELECT SqlServer.Month(o.DatePaid) as
Help! I am using jQuery to make an AJAX call to fill in a
Help! I'm using the ASP.Net Login control on a Login page, but the Login
Help. This don't work after it set menuInput. It always just go to :opties.
help me please with regular expression in ruby. I have a text like 1.
Help settle the debate that's going on in the comments at this question about

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.