2012-10-02 64 views
1
["api",["API","Apiales","Apiaceae","Apicomplexa lifecycle stages","Apia","Apicomplexa","Apidae","APIA Leichhardt Tigers","Apical consonant","Apical membrane"]] 

我該如何解析這個JSON與SBJson解析器的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]; 
+0

你需要支持的iOS版本低於5.0年長?如果不是的話,你應該考慮使用iOS 5中添加的JSON支持。在那之前我使用了SBJsonParser,這很好,但是如果我可以避免的話,我更喜歡避免依賴第三方庫。 – Snips

+0

是的,我需要使用SBJsonParser支持4.1等。我可以找到很多示例代碼,但不是如何解析我的類型的json – user1713954

回答

1

嘗試,

NSArray *results = [json_string JSONValue]; 

NSArray *statuses = [results objectAtIndex:1]; 
+0

Works。非常感謝你! – user1713954