从JSON到NSArray [英] Going from JSON to NSArray
问题描述
我使用的JSON框架位于这里: http://stig.github.com/json-framework 在我的iPhone应用程序。我试图解析出一些数据到一个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)
我从服务器得到JSON字符串确认,这是它的样子:
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"]}
我最后想要的是一个NSArray所以:
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)
("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]);
}
任何帮助将不胜感激。
推荐答案
NSArray *myArray = [dictionary objectForKey:@"users"];
这篇关于从JSON到NSArray的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!