iPhone – Convert NSMutableData to ios JSON object and parse the data

- (void)connectionDidFinishLoading:(NSURLConnection *)connection {
[self.responseData length];
//convert to json
NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:self.responseData options:NSJSONReadingMutableLeaves error:nil];

//show all values
for (id key in dic) {
id value = [dic objectForKey:key];
NSString *keyAsString = (NSString *)key;
NSString *valueAsString = (NSString *)value;

NSLog(@"key: %@", keyAsString);
NSLog(@"value: %@", valueAsString);
}

NSArray *results = [dic objectForKey:@"results"];
for (NSDictionary *result in results) {
NSString *name = [result objectForKey:@"name"];

[nameList addObject:name];
NSLog(@"Name : %@", name);
}

One thought on “iPhone – Convert NSMutableData to ios JSON object and parse the data

Leave a comment