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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T06:49:01+00:00 2026-06-03T06:49:01+00:00

could you help me and tell me why my entity is empty ? i’m

  • 0

could you help me and tell me why my entity is empty ?

i’m populating my entity with my JSON, my entity’s attributes has the same name as in my JSON

this is my code to populate my entity :

  NSManagedObjectContext *cxt = [self managedObjectContext];
    NSManagedObject *newBoxes = [NSEntityDescription insertNewObjectForEntityForName:@"Boxes" inManagedObjectContext:cxt];
    NSDictionary *parsedFeed = [[newBoxes entity] attributesByName];
    for (NSString *key in parsedFeed) {
        id value = [parsedFeed objectForKey:key];
        // Don't assign NSNull, it will break assignments to NSString, etc.
        if (value && [value isKindOfClass:[NSNull class]])
            value = nil;

        @try {
            [Boxes setValue:value forKey:key];
        } @catch (NSException *exception) {
            // Exception means such attribute is not defined in the class or some other error.
        }
    }

    NSError *err;
    if (![cxt save:&err]) {
        NSLog(@"An error has occured: %@", [err localizedDescription]);
    }



NSLog(@"ENTITY  %@", newBoxes);

this is the result of my NSLOG :

2012-04-30 11:16:23.352 Wonder[9987:fb03] ENTITY  <Boxes: 0x6d87330> (entity: Boxes; id: 0x6d8b010 <x-coredata://EFDCC0BA-644D-42AC-8DE8-452F02B7C680/Boxes/p26> ; data: {
    codeArticle = nil;
    descriptionBox = nil;
    dlu = 0;
    kindBox = nil;
    nameBox = nil;
    nbActivities = 0;
    note = 0;
    priceBox = 0;
    texteMarketing = nil;
    typeBox = nil;
})

this is my JSON :

{
    "totalBox":{
        "boxes":[
        {
         "codeArticle": "WPCDE01C412L",
         "nameBox": "boxName",
         "texteMarketing": "boxTextMarketing",
         "descriptionBox" : "boxDescritpion",
         "nbActivities": 1650,
         "kindBox": "boxKind",
         "typeBox": "boxType",
         "priceBox": 20,
         "dlu": 2014,
         "note": 3
        },
        {
         "codeArticle": "BOOYAKA!!",
         "nameBox": "boxNameName",
         "texteMarketing": "boxTextMarketing",
         "descriptionBox" : "boxDescritpion",
         "nbActivities": 1650,
         "kindBox": "boxKind",
         "typeBox": "boxType",
         "priceBox": 39,
         "dlu": 2014,
         "note": 3
         }
        ]
            }
}

this is my entity :

enter image description here

EDIT : i give my JSON, so i should “tell” my coredata what it should read to populate my entity, right ?

dataToDisplay = [[NSMutableArray alloc] init];

//récupération du chemin vers le fichier contenant le JSON
NSString *filePath = [[NSBundle mainBundle] pathForResource:@"JSON" ofType:@"txt"];

//création d'un string avec le contenu du JSON
NSString *myJSON = [[NSString alloc] initWithContentsOfFile:filePath encoding:NSUTF8StringEncoding error:NULL];   

//Parsage du JSON à l'aide du framework importé
NSDictionary *json    = [myJSON JSONValue];

//récupération  du total des Boxes
NSDictionary *resultats    = [json objectForKey:@"totalBox"];
  • 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-03T06:49:02+00:00Added an answer on June 3, 2026 at 6:49 am

    In the code above you are trying to set values on a non object.

    [Boxes setValue:value forKey:key];
    

    Should be

    [newBoxes setValue:value forKey:key];
    

    I would recommend that you take a look at http://rentzsch.github.com/mogenerator/ and this super useful article on JSON and CoreData http://www.cimgf.com/2012/01/11/handling-incoming-json-redux/

    Cheers
    mbogh

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

Sidebar

Related Questions

Could anyone please tell how jre directory help in the running java programs? I'm
What could help me in helping writing highly compact(least byte code count) programs in
I wonder is anyone can look at this code and tell me why calling
Could someone please help and tell me how to use protocol buffers. Actually I
Could someone please help and tell me how to include IEEE mathematical functions in
I would be grateful if anybody could help me out with this. I have
I would be very grateful if someone could help me break through this issue
This has been a hard problem to diagnose and I was hoping someone could
I was hoping someone could help clarify my options regarding refactoring methods from code-behinds
Could you help me and tell if im using the using statement correctly in

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.