How to parse nested JSON objects with JSON framework and Objective-C/iPhone/Xcode?

前端 未结 4 1909
旧时难觅i
旧时难觅i 2020-12-16 05:48

I\'m writing an iPhone native app using the JSON framework.

My app is accessing web services using JSON. The JSON data we send has nested objects, below is an exampl

4条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-16 06:45

        NSString* aStr;
        aStr = [[NSString alloc] initWithData:data encoding:NSASCIIStringEncoding];
        NSDictionary *dictionary = [aStr JSONValue];
        NSArray *keys = [dictionary allKeys];
    
        // values in foreach loop
        for (NSString *key in keys) {
        NSArray *items = (NSArray *) [dictionary objectForKey:key];  
    
            for (id *item in items) {  
    
    
                NSString* aStrs=  item;
                NSLog(@" test %@", aStrs);
    
                NSDictionary *dict = aStrs;
                NSArray *k = [dict allKeys];
    
            for (id *it in k) {  
                                NSLog(@"the  child item: %@", [NSString stringWithFormat:@"Child Item -> %@ value %@", (NSDictionary *) it,[dict objectForKey:it]]);                
                            }
    

提交回复
热议问题