我如何解析这个JSON数据?

时间:2012-10-02 09:43:43

标签: ios json

  ["api",["API","Apiales","Apiaceae","Apicomplexa lifecycle stages","Apia","Apicomplexa","Apidae","APIA Leichhardt Tigers","Apical consonant","Apical membrane"]]

如何使用SBJson Parser for iOS解析此JSON。我需要它只是一个只有这些值的数组:

  "API","Apiales","Apiaceae","Apicomplexa   lifecyclestages","Apia","Apicomplexa","Apidae","APIA Leichhardt Tigers","Apical consonant","Apical membrane"

我目前的代码:

SBJsonParser *parser = [[SBJsonParser alloc] init];

// Prepare URL request to download statuses from Twitter
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"http://en.wikipedia.org/w/api.php?action=opensearch&search=dj&limit=100&namespace=0&format=json"]];

// Perform request and get JSON back as a NSData object
NSData *response = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:nil];

// Get JSON as a NSString from NSData response
NSString *json_string = [[NSString alloc] initWithData:response encoding:NSUTF8StringEncoding];

NSDictionary *results = [json_string JSONValue];

NSArray *statuses = [parser objectWithString:json_string error:nil];

1 个答案:

答案 0 :(得分:1)

尝试,

NSArray *results = [json_string JSONValue];

NSArray *statuses = [results objectAtIndex:1];