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

  • Home
  • SEARCH
  • 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 695239
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T02:56:20+00:00 2026-05-14T02:56:20+00:00

All of the data on my application is pulled through an API via JSON.

  • 0

All of the data on my application is pulled through an API via JSON. The nature of a good percentage of this data is that it doesn’t change very often. So to go and make JSON requests to get a list of data that doesn’t change much didn’t seem all that appealing.

I’m looking for the most sensible option to have this JSON saved onto the iPhone in some sort of persistent data store. Obviously one plus of persisting the data would be to provide it when the phone can’t access the API.

I’ve looked at a few examples of having JSON and CoreData interact, for example, but it seems that they only describe transforming NSManagedObjects into JSON. If I can transform JSON into CoreData, my only problem would be being able to change that data when the data from the API does change.

(Or, maybe this is all just silly.)

  • 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-14T02:56:20+00:00Added an answer on May 14, 2026 at 2:56 am

    For some conceptual reading, you may want to read documentation about Efficiently Importing Data, especially “Find-or-create”. See a previous similar question.

    Getting JSON and saving it as Core Data locally is highly reasonable. How I do it is in two stages:

    1. convert JSON to native Cocoa data types (NSDictionary and NSArray)
    2. convert NS* into Core Data object

    Two good frameworks for converting between JSON and NS* are json-framework and TouchJSON. The below example is based on json-framework.

    Let’s say you get an array of some objects from JSON. You’d then do:

    NSArray *objects = [jsonStringYouGotFromServer JSONValue];
    for (NSDictionary *_object in objects) {
        CDObjectType *cdObject = [self cdObjectFromDictionary:_object];
        // cdObject is now a full-featured Core Data object
    }
    

    the cdObjectFromDictionary might be something like this:

    - (CDObjectType *) cdObjectFromDictionary:(NSDictionary *)dict {
    
        CDObjectType *object = [NSEntityDescription
                  insertNewObjectForEntityForName:@"Object"
                  inManagedObjectContext:moc];
    
        NSDictionary *attributes = [[NSEntityDescription
            entityForName:@"Object"
            inManagedObjectContext:moc] attributesByName];
    
        for (NSString *attr in attributes) {            
            [object setValue:[dict valueForKey:attr] forKey:attr];                            
        }
    
        return object;
    }
    

    The above assumes that the attribute names in your JSON and Core Data model are the same and that the data types match (i.e JSON numbers are Core Data NSNumbers etc). The above code works nicely even if the model changes.

    The above code does not consider how to test if the object already exists locally, but you can imagine how to add that. You must have an object ID of some form in your model, and you can see if the object exists locally before adding it, or whether existing object needs to be updated.

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

Sidebar

Related Questions

I have a C# Application I am creating that stores all data in SQL
In my web application there is a process that queries data from all over
Possible Duplicate: VS2008 Setup Project: Shared (By All Users) Application Data Files? Please can
Is there a relatively simple way to change all the data in a JTable?
I am writing a Catalyst web application that presents some data that does not
I want to write an Android application that can display some data received(polled) from
I would like to wipe out all data for a specific kind in Google
I would like to force svcutil to generate all data contracts in an assembly
In my code, I want to view all data from a CSV in table
The question gives all necessary data: what is an efficient algorithm to generate a

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.