Search code examples
objective-ccocoacoldfusioncoldfusion-9

Parse Coldfusion 9 generated JSON response in Cocoa Obj-C


I have an NSDictionary instance created via

NSDictionary *responseDict = [NSJSONSerialization JSONObjectWithData:data options:0 error:nil];

from a Coldfusion generated JSON response with a output similar to this:

{"ROWCOUNT":1,"COLUMNS":["SUBSCRIBERID","FIRSTNAME","LASTNAME"],"DATA":{"SUBSCRIBERID":[
27775],"FIRSTNAME":["John"],"LASTNAME":["Doe"]}}

What I'm trying to do is enumerate the DATA objects but struggling with the syntax.

Any guidance appreciated.


Solution

  • Your "DATA" object is just a dict, so doing this would enumerate that dict:

    NSDictionary *dataDict = [response objectForKey:@"DATA"];    
    [dataDict enumerateKeysAndObjectsUsingBlock:^(id key, id obj, BOOL *stop) {
            // do your work here 
    }];