I have the following json:
http://www.adityaherlambang.me/webservice.php?user=2&num=10&format=json
I would like to get all the name in this data by the f
It seems to me that when you create the "users" dictionary you are actually creating a "user" dictionary.
NSDictionary *users = [[results objectForKey:@"users"] objectForKey:@"user"];//crating users dictionary with 1 "user" inside.
EDIT
in second view. why don't you just iterate the "result" dictionary? like that -
for (NSDictionary *user in result){
//NSLog(@"key:%@, value:%@", user, [user objectForKey:user]);
NSString *title = [users objectForKey:@"NAME"];
NSLog(@"%@", title);
}
hope it will help shani
NSDictionary *results = [responseString JSONValue];
NSDictionary *users = [results objectForKey:@"users"] objectForKey:@"user"];
-[__NSArrayM objectForKey:]: unrecognized selector sent to instance
exception.The first step is to understand your JSON data. It is structured as follows:
If you want to iterate over the users and print the value for the "NAME" key, follow the example below.
NSString *responseString = [[NSString alloc] initWithData:responseData
encoding:NSUTF8StringEncoding];
// 1. the top level value is an array
NSArray *results = [responseString JSONValue];
// 2. each element in the array is an object/dictionary with
// a single key called "user"
for (NSDictionary *element in results) {
// 3. the value of the "user" key is itself another object/dictionary
// with various key-value pairs
NSDictionary *user = [element objectForKey:@"user"];
NSString *title = [user objectForKey:@"NAME"];
NSLog(@"%@", title);
}