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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T22:51:23+00:00 2026-05-26T22:51:23+00:00

I have a JSON that looks like this here: { key1:[ { desc:key1decs., duration:50;

  • 0

I have a JSON that looks like this here:

 { 
  "key1":[ 
  { 
    "desc":"key1decs.", 
    "duration":50; 
  },{ 
    "desc":"", 
    "duration":90; 
  },{ 
    "desc":"Kurz vor...", 
    "duration":30; 
  } 
 ], 
 "key2":[ 
  { 
    "desc":"key2decs.", 
    "duration":50; 
  },{ 
    "desc":"blabla", 
    "duration":90; 
  } 
] 
} 

I am trying to do a mapping. But I’m stuck because of different
unknown/arbitrary keys. I tried mapping without KVC, but it seems not
to be working. Gives me error:
Failed transformation of value at keyPath ‘key1.desc’. No strategy for
transforming from ‘__NSArrayI’ to ‘NSString’. and so on for every
attribute.
I saw on the web that mapping without KVC doesn’t support arrays as
inner structures. Plz, help. What is right approach here?

EDIT:
ENtity:

@interface Sendung : NSObject

 @property (nonatomic, strong) NSString *description;
 @property (nonatomic, strong) NSNumber *duration;
 @property (nonatomic, strong) NSNumber *sendungkey;
@end;

Controller:

 RKObjectMapping* mapping = [RKObjectMapping mappingForClass:[Sendung class]];
 mapping.forceCollectionMapping = YES;
[mapping mapKeyOfNestedDictionaryToAttribute:@"sendungkey"];
[mapping mapKeyPath:@"(sendungkey).desc" toAttribute:@"description"];
[mapping mapKeyPath:@"(sendungkey).duration" toAttribute:@"duration"];
[[RKObjectManager sharedManager].mappingProvider addObjectMapping:mapping ];
 mapping = [[RKObjectManager sharedManager].mappingProvider objectMappingForClass:[Sendung class] ];
[[RKObjectManager sharedManager] loadObjectsAtResourcePath:url objectMapping:mapping delegate:self];

This is what I get when NSlogin result: (
(null),
(null),
(null),
(null),
(null)
)

  • 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-26T22:51:24+00:00Added an answer on May 26, 2026 at 10:51 pm

    I believe you miss one ‘level’ of your mapping. If you take a closer look at your input, you have an dictionary (key1), which contents is not single ‘Sendung‘ but an array of such objects. Thus, you can’t map contents of the key1 directly to Sendung ivars, rather than create new class, eg SendungResult.

    @interface SendungResult : NSObject
        @property (nonatomic, strong) NSString *keyName;
        @property (nonatomic, strong) NSArray *sendungs;
    @end
    

    and map the contents of key1 to SendungResult sendungs array using the relationship mapping you use now directly.

    EDIT: I’m extending the answer as follows:

    As i said earlier, you are trying to map a collection of objects into a single instance, so this can not work. Instead, you have to create a SendungResult that will hold an array of Sendung instances for one key. So in your example, you’ll end up with two SendungResult instances (one will hold three Sendungs – those nested under "key1" and the second one just two, nested under "key2"). You can’t map this kind of a structure into just once class, you have to nest them same way as your JSON is nested. The Sendung class is basically unchanged.

    Now for the mapping. You need to define two mappings, one will map the contents of your root JSON into two SendungResult (one for each key) and the second mapping will map the inner part into individual Sendung instances.

    We start with the inner mapping.

    RKObjectMapping *sendungMapping = [RKObjectMapping mappingForClass:[Sendung class]];
    [sendungMapping mapKeyPath:@"desc" toAttribute:@"desc"];
    [sendungMapping mapKeyPath:@"duration" toAttribute:@"duration"];
    [[[RKObjectManager sharedManager] mappingProvider] addObjectMapping:sendungMapping];
    

    Nothing really interesting here, we just map the keypaths to your properties. Now for the outer part.

    RKObjectMapping *resultMapping = [RKObjectMapping mappingForClass:[SendungResult class]];
    [resultMapping setForceCollectionMapping:YES];
    [resultMapping mapKeyOfNestedDictionaryToAttribute:@"keyName"];
    [resultMapping mapKeyPath:@"(keyName)" toRelationship:@"sendungs" withMapping:sendungMapping];
    [[[RKObjectManager sharedManager] mappingProvider] addObjectMapping:resultMapping];
    

    We tell RestKit to map contents of the keyName keyPath to sendungs property found on SendungResult class with the mapping defined earlier.

    Now we can fetch the data

    [[RKObjectManager sharedManager]  loadObjectsAtResourcePath:@"test.js" objectMapping:resultMapping delegate:self];
    

    The RestKit will create two SendungResult instances, each array contains the inner Sendung classes (3 and 2, respectively)

    Note: I strongly suggest you to read RestKit Object Mapping documentation. Also, JSONLint found your JSON to be invalid, i had to remove the semicolons. So be sure to use valid json.

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

Sidebar

Related Questions

I have JSON text that looks like this: { ok: true, totalPages: 256, arReports:
I have a JSON string that looks like this: { package1: { type: envelope,
I have to process JSON files that looks like this: \u0432\u043b\u0430\u0434\u043e\u043c <b>\u043f\u0443\u0442\u0438\u043c<\/b> \u043d\u0430\u0447 Unfortunately,
Greetings all, I have some JSON code that looks like this: { playlist: [
I have a manifest.json file that looks like this: { name: Zend Debugger Extension,
Here's an interesting problem: I have some jQuery that looks like this: $(document).ready(function() {
I have a JSON string (from PHP's json_encode() that looks like this: [{id: 1,
I have a function to sort a JSON object that looks like this: function
I have some JSON data that looks like this: { data: [{ name:John Smith,
I have an array left over after parsing JSON that looks like ( -122.1407313,

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.