Search code examples
jsonparsingnsdictionarynsjsonserialization

Parsing JSON object in Objective-C


Currently I have a JSON object, but when I parse the startLabel key paired element within VALUES, I return an nsdictionary with the first element being NULL and its keys being the values.

Here is the JSON object

(
        {
        values =         (
                                {
                        start = 1370066400;
                        startLabel = 20130601000000;
                        value = "1.000000047497";
                    },
                                {
                        start = 1370067300;
                        startLabel = 20130601001500;
                        value = "1.000000047497";
                    },
                                {
                        start = 1370068200;
                        startLabel = 20130601003000;
                        value = "1.000000047497";
                    }
             );
       }
)

Currently, this is the NSLog output of the dictionary object "dict"

(
"<null>",
    (
    20130601000000,
    20130601001500,
    20130601003000,
    20130601004500,
    20130601010000,
    20130601011500,
    20130601013000,
    20130601014500,
    20130601020000,
    20130601021500,
    20130601023000,
    20130601024500,
    20130601030000,
    20130601031500,
    20130601033000,
    20130601034500,
    20130601040000,
    20130601041500,
    20130601043000,
    20130601044500,
    20130601050000,
    20130601051500,
    20130601053000,
    20130601054500,
    20130601060000,
    20130601061500,
    20130601063000,
    20130601064500,
    20130601070000,
    20130601071500,
    20130601073000,
    20130601074500,
    20130601080000,
    20130601081500,
    20130601083000,
    20130601084500,
    20130601090000,
    20130601091500,
    20130601093000,
    20130601094500,
    20130601100000,
    20130601101500,
    20130601103000,
    20130601104500,
    20130601110000,
    20130601111500,
    20130601113000,
    20130601114500,
    20130601120000,
    20130601121500,
    20130601123000,
    20130601124500,
    20130601130000,
    20130601131500,
    20130601133000,
    20130601134500,
    20130601140000,
    20130601141500,
    20130601143000,
    20130601144500,
    20130601150000,
    20130601151500,
    20130601153000,
    20130601154500,
    20130601160000,
    20130601161500,
    20130601163000,
    20130601164500,
    20130601170000,
    20130601171500,
    20130601173000,
    20130601174500,
    20130601180000,
    20130601181500,
    20130601183000,
    20130601184500,
    20130601190000,
    20130601191500,
    20130601193000,
    20130601194500,
    20130601200000,
    20130601201500,
    20130601203000,
    20130601204500,
    20130601210000,
    20130601211500,
    20130601213000,
    20130601214500,
    20130601220000,
    20130601221500,
    20130601223000,
    20130601224500,
    20130601230000,
    20130601231500,
    20130601233000,
    20130601234500
    )
)

How do I obtain a dictionary object that doesn't contain a null as the first Key?

Here is the code I use:

NSDictionary* json = [NSJSONSerialization JSONObjectWithData:responseData options:kNilOptions error:&error];

NSArray* data = [json objectForKey:@"fields"];
NSDictionary *graphStartDate = [data valueForKeyPath:@"values.startLabel"];

If more code is needed, please ask :) But that's basically it.


Solution

  • Issue solve.....

    I made another NSArray that accessed the second key element of the given dictionary object and I was able to get all the given values.....

    Kinda a hack workaround and makes the program less efficient....

    NSArray *array = [graphStartDate objectAtIndex:1];
    

    Not exactly sure how to get rid of the null object but I'll go into more detail with the developers who wrote the web server in javascript to understand whats REALLY going on....