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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T22:02:50+00:00 2026-05-31T22:02:50+00:00

I have an App using core data with 3 entities with very similar attributes.

  • 0

I have an App using core data with 3 entities with very similar attributes. The relationship is such as:

Branch ->> Menu ->> Category ->> FoodItem

Each entity has an associated class: example

enter image description here

I am trying to generate JSON representation of the data in sqlite database.

//gets a single menu record which has some categories and each of these have some food items
id obj = [NSArray arrayWithObject:[[DataStore singleton] getHomeMenu]]; 

NSError *err;
NSData *jsonData = [NSJSONSerialization dataWithJSONObject:obj options:NSJSONWritingPrettyPrinted error:&err];

NSLog(@"JSON = %@", [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding]);

But instead of JSON, i get a SIGABRT error.

*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Invalid type in JSON write (Menu)'

Any ideas how to fix it or how to make the entity classes (Branch, Menu etc) JSON serialization compatible?

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

    That’s because your “Menu” class is not serializable in JSON. Bascially the language doesn’t know how your object should be represented in JSON (which fields to include, how to represent references to other objects…)

    From the NSJSONSerialization Class Reference

    An object that may be converted to JSON must have the following
    properties:

    • The top level object is an NSArray or NSDictionary.
    • All objects are instances of NSString, NSNumber, NSArray, NSDictionary, or NSNull.
    • All dictionary keys are instances of NSString.
    • Numbers are not NaN or infinity.

    This means that the language knows how to serialize dictionaries. So a simple way to get a JSON representation from your menu is to provide a Dictionary representation of your Menu instances, which you will then serialize into JSON:

    - (NSDictionary *)dictionaryFromMenu:(Menu)menu {
        [NSDictionary dictionaryWithObjectsAndKeys:[menu.dateUpdated description],@"dateUpdated",
        menu.categoryId, @"categoryId",
        //... add all the Menu properties you want to include here
        nil];
    }
    

    And you could will use it like this :

    NSDictionary *menuDictionary = [self dictionaryFromMenu:[[DataStore singleton] getHomeMenu]]; 
    
    NSError *err;
    NSData *jsonData = [NSJSONSerialization dataWithJSONObject:menuDictionary options:NSJSONWritingPrettyPrinted error:&err];
    
    NSLog(@"JSON = %@", [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding]);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using core data in my app. I have two entities that are related:
I am creating an iOS 5 app using Core Data. I have two entities
I am building a toy app using core data for two entities Log (attributes
I am creating Travel guide app using core data. I have 4 entities CITY
I have developed my app using core data. It works fine in the simulator.
I have a fairly complex Core Data database with many entities, attributes and relationships.
I am using Core Data for my app and I have a model Reservation
I'm using Core data on my app ok, i have a problem when saving
I am using Core Data for my iPhone app. My attributes are set with
I have a cocoa-touch app, using the core data framework. I've created a xcdatamodel

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.