Search code examples
iosobjective-cjsonnsdictionarynsdata

Extracting one property out of a JSON response


I'm horrible at JSON. I don't understand a single thing. My JSON response looks like this:

 {
    ID = 1;
    EDate = "<null>";
    SelectedDay = "/Date(-62135596800000)/";
    End = "14.09.2013 15:00:00";
    Start = "14.09.2013 07:00:00";
    SDate = "<null>";
},
    {
    ID = 1;
    EDate = "<null>";
    SelectedDay = "/Date(-62135596800000)/";
    End = "14.09.2013 16:00:00";
    Start = "14.09.2013 07:00:00";
    SDate = "<null>";
},

In both NSData and NSDictionary. How can I loop trough, for example, the "End" property of each object, and add them to an array?

Edit:

I log from this code:

NSDictionary *dict = [NSJSONSerialization JSONObjectWithData:result.data options:kNilOptions error:&error];

    NSLog(@"Response: %@",dict);

and the complete log is: enter image description here


Solution

  • This JSON seems to be an array of dictionaries. Try with:

    NSMutableArray *endValuesArray = [[NSMutableArray alloc] init];
    
    for (NSDictionary *dictionary in JSONArray) {
    
         [endValuesArray addObject:[dictionary valueForKey:@"End"]];
    
    }
    

    Where JSONArray is the array obtained after NSJSONSerialization.