简体   繁体   中英

Going from JSON to NSArray

I'm using the JSON framework found here: http://stig.github.com/json-framework in my iPhone app. I'm trying to parse out some data into an NSArray (order matters so a dictionary won't work)

I get the JSON string ok from the server and this is what it looks like:

{"users":["example1@examle.com","example2@example.com","example3@example.com"]}

what I would like to end up with is an NSArray so that:

myArray[0] == "example1@example.com"
myArray[1] == "example2@example.com"
myArray[3] == "example3@example.com"

this should be really easy, but it's not for me the closest I can get is this output:

("example1@example.com","example2@example.com","example3@example.com")

from this code

NSDictionary *dictionary = [jsonString JSONValue];
for(NSString *key in dictionary){
    NSLog(@"Dictionary value for \"%@\" is \"%@\"",key, [dictionary objectForKey:key]);
}

any help would be appreciated!

NSArray *myArray = [dictionary objectForKey:@"users"];

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM