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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T06:10:10+00:00 2026-06-11T06:10:10+00:00

The blog post SAVING JSON TO CORE DATA has some great tips for converting

  • 0

The blog post SAVING JSON TO CORE DATA has some great tips for converting a JSON response into a Core Data entity. What I want to do is a little bit more specific. I’d like to take a JSON response and convert the objects using the methods in the blog post into an NSObject with properties representing the response objects. The problem that I’m running into are nested properties of the object. Take this JSON response as an example:

http://us.battle.net/api/d3/profile/rnystrom-1254/

Using the methods described in the blog post, simple properties like “name” and “level” are easy to convert to NSString and NSNumber objects. However the problem arises when looking at more complex parts of the response: nested arrays/dictionaries.

The only solution I’ve found is to hand-code the finding and converting of all of these properties which I feel is a really poor practice. Here’s an excerpt of what I’m doing:

    NSDictionary *skillsDictionary = json[@"skills"];
    if ([skillsDictionary isKindOfClass:[NSDictionary class]]) {
        NSArray *activeArray = skillsDictionary[@"active"];
        NSArray *passiveArray = skillsDictionary[@"passive"];

        NSMutableArray *mutActives = [NSMutableArray array];
        NSMutableArray *mutPassives = [NSMutableArray array];

        if ([activeArray isKindOfClass:[NSArray class]]) {
            [activeArray enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
                if ([obj isKindOfClass:[NSDictionary class]]) {
                    NSDictionary *activeJSON = (NSDictionary*)obj;
                    D3Skill *skill = [D3Skill activeSkillFromJSON:activeJSON];
                    if (skill) {
                        [mutActives addObject:skill];
                    }
                }
            }];
        }

        if ([passiveArray isKindOfClass:[NSArray class]]) {
            [passiveArray enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
                if ([obj isKindOfClass:[NSDictionary class]]) {
                    NSDictionary *passiveJSON = (NSDictionary*)obj;
                    D3Skill *skill = [D3Skill passiveSkillFromJSON:passiveJSON];
                    if (skill) {
                        [mutPassives addObject:skill];
                    }
                }
            }];
        }

        self.activeSkills = mutActives;
        self.passiveSkills = mutPassives;
    }
  • 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-11T06:10:12+00:00Added an answer on June 11, 2026 at 6:10 am

    I use the SBJSON library and ASIHttpRequest to fetch and consume JSONs from a webservice of my own design, if I understand your question correctly, you’d just need to do something like this:

    NSString *responseJSONasString = [fetchRequest responseString]; 
    NSDictionary *itemResponseArray = [responseJSONasString JSONValue];
    

    The SBJSON library will do the converting for you into NSObjects and put them into Arrays/Dictionaries using key:value coding on the JSON elements, so with the JSON you provided I could get the first hero’s name with:

    NSArray *heroes = [itemResponseArray objectForKey:@"heroes"];
    NSDictionary *firstHero = [heroes objectAtIndex:0];
    NSString *heroName = [firstHero objectForKey:"name"];
    

    SBJson can be found here: http://stig.github.com/json-framework/

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

Sidebar

Related Questions

A client of mine has a food blog hosted on WordPress. Each post entry
I ran into this blog post today. I'll summarize. The blogger is commenting on
The blog post introducing the new syntax said that the old MLish syntax would
This blog post of December 2008 says that rubygems is broken on Debian-based systems.
Have a painfully simple blog Post creator, and I'm trying to check if the
On this blog post , it's said that the minimum memory usage of a
An informative-sounding blog post from 2006 states these facts about using native prepared statements
See my blog post for excerpt from Java Posse #386 - Newscast for May
I've read the blog post at letitcrash.com about Play-mini and Akka ( this one
I remember reading a blog post about a group that had taken a branch

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.