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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T14:43:39+00:00 2026-05-23T14:43:39+00:00

I am trying to dynamically map JSON information into different objects. But I can’t

  • 0

I am trying to dynamically map JSON information into different objects. But I can’t figure out quite how to get the whole pointer situation under control, as what I was hoping would work does not.

So far my methodology has been to create a dictionary for each object, mapping the variable pointers to the equivalent JSON keys. In my JSON mapper, I have a method, parseJSONFromDictionary:withObject that is supposed to iterate over the dictionary returned by SBJSON‘s JSONValue and assign the appropriate values to the appropriate variables in the given object.

-(NSObject *)parseJSONFromDictionary:(NSDictionary *)dict withObject:(NSObject *)start{
    for (NSString *key in dict) {
        if ([[self.mappings objectForKey:key] isMemberOfClass:[NSString class]]) {
            start.[self.mappings objectForKey:key] = [[dict valueForKey:key] stringValue];
        }
    }
    return start;
}

mappings is the dictionary that has the variables and json keys, and the dict is what gets returned from the json parser.

The big problem is that I can’t do start.[self.mappings objectForKey:key]. I don’t know much about C, and clearly I don’t know enough about pointers, so how would I go about creating this kind of system? I know that’s not the right way to do this, but what is the right way? I know it can be done, as RestKit does it, but they don’t support OAuth so I sadly can’t use their lovely framework.

The reason I’m going this route is because the API I’m working with is currently in its alpha stage. I want to be able to easily adapt to any future changes without having to rewrite many lines of code. I also want to start programming DRY-ly. I know JSON parsing is very repetitive, and I’d like to find a way to reduce the amount of overhead.

Thanks for any and all help!


EDIT: It seems there is some confusion as to what I’m asking. I do not need help parsing JSON. I’m using SBJSON already. I do not need help making requests, I am already using JDG’s OAuthConsumer framework. I can only use frameworks that support OAuth 2.0.

I do need help figuring out how to prevent this:

-(Class1 *)parseJsonForClass1:(NSString *)inputString {
    NSDictionary *outputDict = [inputString JSONValue];
    Class1 *instance1 = [self mapObjectsForClass1From:outputDict];
    return instance1;
}

-(Class2 *)parseJsonForClass2:(NSString *)inputString {
    NSDictionary *outputDict = [inputString JSONValue];
    Class2 *instance2 = [self mapObjectsForClass2From:outputDict];
    return instance2;
}

-(Class3 *)parseJsonForClass3:(NSString *)inputString {
    NSDictionary *outputDict = [inputString JSONValue];
    Class2 *instance3 = [self mapObjectsForClass3From:outputDict];
    return instance3;
}

-(Class1 *)mapObjectsForClass1From:(NSDictionary *)dict {
    Class1 *object1 = [[Class1 alloc] init];
    object1.name = [[dict valueForKey:@"name"] stringValue];
    object1.date = [[dict valueForKey:@"date"] stringValue];
    object1.objId = [[dict valueForKey:@"id"] intValue];

    return object1;
}

-(Class2 *)mapObjectsForClass2From:(NSDictionary *)dict {
    Class2 *object2 = [[Class2 alloc] init];
    object2.something = [[dict valueForKey:@"something"] stringValue];
    object2.title = [[dict valueForKey:@"title"] stringValue];
    object2.imageUrl = [[dict valueForKey:@"image_url"] stringValue];

    return object2;
}

-(Class3 *)mapObjectsForClass3From:(NSDictionary *)dict {
    Class3 *object3 = [[Class3 alloc] init];
    object3.foo = [[dict valueForKey:@"bar"] stringValue];
    object3.flag = [[dict valueForKey:@"is_member"] boolValue];
    object3.obj1 = [[Class1 alloc] init];
    object3.obj1 = [self mapOjectsForClass1From:[dict objectForKey:@"name1"]];

    return object3;
}

So please let me know if you have any suggestions on how to combine these kinds of methods into 1 method…

  • 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-23T14:43:40+00:00Added an answer on May 23, 2026 at 2:43 pm

    I actually recently saw someone doing this using Objective Resources. While it’s a nice way to access objects, some of the implementation can get messy. And you have to use everything the server sends you, whether you like it or not. I’m going to stay away from this right now.

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

Sidebar

Related Questions

Currently I am trying to figure out how I can add dynamic query string
I'm trying to put different images (.jpg , .png) dynamically into a ListView from
Question I am trying to dynamically get the default for a type that is
Trying to make a make generic select control that I can dynamically add elements
I am trying to get a dynamically loaded LinkButton to fire a postback event,
I'm trying to use jQuery to dynamically create an image map, and I ran
I am trying to dynamically filter out content using checkboxes and jquery. Being new
I'm trying to dynamically get a databases Table structure using only C# code as
I am trying to create a normal map in opengl that I can load
Trying to dynamically change the message of an AlertDialog. For some reason I get

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.