1

The JSON that I am parsing can be found here 'redacted'.

I can correctly grab all of the objects from this JSON except notifications and devices. I am having a lot of trouble being able to get the array of device dictionaries containing 'deviceId's. My code right now looks like this

dispatch_async(kBgQueue, ^{
    NSData* data = [NSData dataWithContentsOfURL:
                    iViuListOfCustomersURL];

    [self performSelectorOnMainThread:@selector(fetchedData:)
                          withObject:data waitUntilDone:NO];
});




- (void) fetchedData:(NSData *)responseData {
NSError* error;
NSDictionary* json;
    json = [NSJSONSerialization
                          JSONObjectWithData:responseData // 1

                          options:kNilOptions
                          error:&error]; 

    NSArray* customers = json; 


    for(int i = 0; i < customers.count ; i++){
        NSDictionary *customer = [customers objectAtIndex:i];
        cmsServer = [customer objectForKey:@"cmsServer"]; 
        iconUrl = [NSURL URLWithString:[customer objectForKey:@"iconUrl"]];
        wideLogo = [customer objectForKey:@"wideLogo"]; 
        customerNo = [NSNumber numberWithInt:[[customer objectForKey:@"customerNo"] intValue]];
        placeName = [customer objectForKey:@"placeName"];
        distance = [NSNumber numberWithFloat:[[customer objectForKey:@"distance"] floatValue]];
        placeId = [NSNumber numberWithInt:[[customer objectForKey:@"placeId"] intValue]];
        address = [customer objectForKey:@"address"];
        cmsName = [customer objectForKey:@"cmsName"]; 
        hasLocations = [NSNumber numberWithInt:[[customer objectForKey:@"hasLocations"]intValue]];
        isFavorite = [NSNumber numberWithInt:[[customer objectForKey:@"isFavorite"] intValue]];
        longitude = [NSNumber numberWithFloat:[[customer objectForKey:@"longitude"] floatValue]];
        latitude = [NSNumber numberWithFloat:[[customer objectForKey:@"latitude"] floatValue]];
        hasArtifacts = [NSNumber numberWithInt:[[customer objectForKey:@"hasArtifacts"]intValue]];

        // I have tried a number of things and this was what I had for the last try.
        devices = [NSArray arrayWithObject:[customer objectForKey:@"devices"]];
        NSLog(@"%@",devices.count);
    }

}

I am relatively new to objective-c and wanted to figure this out on my own but I have spent too much time on this issue and I cannot continue without these device IDs.

Thank you!

1 Answer 1

1

I don't know if it will make a difference but have you tried:

devices = [NSArray arrayWithArray:[customer objectForKey:@"devices"]];

The other thing you can try is going through the elements in it and adding them one by one into devices:

for(DeviceObject *deviceObject in [customer objectForKey:@"devices"])
{
  [devices addObject:deviceObject];
}

The other thing you can look into is the empty values you pass sometimes in your json.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.