2011-05-19 67 views
1
{"response":[33689822,64091979,69682048,74160161]} 

-JSON解析的iOS串

- (void)requestCompleted:(ASIHTTPRequest *)request 
{ 
    NSString *responseString = [request responseString]; 
    NSLog(@"okRequest|| %@",responseString); 

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

    // Prepare URL request to download statuses from Twitter 

    // Get JSON as a NSString from NSData response 
    NSString *json_string = [[NSString alloc] initWithString:responseString]; 

    // parse the JSON response into an object 
    // Here we're using NSArray since we're parsing an array of JSON status objects 
    NSArray *statuses = [parser objectWithString:json_string error:nil]; 

    // Each element in statuses is a single status 
    // represented as a NSDictionary 
    for (NSDictionary *status in statuses) 
    { 
     //all other func.. 
     NSLog(@"%@ ", status);///This func prints only "response" 
    } 
} 

我怎樣才能在 「響應」 數字陣列? (33689822,64091979,69682048,74160161)

回答

1

嘗試這種情況:

for (NSNumber *number in [statuses objectForKey:@"response"]) { 
    NSLog(@"%@", number); 
} 
+0

非常感謝!這個工程! – SevenDays 2011-05-19 07:22:14

0

嘗試直接使用JSONFragmentValue。

NSString *response=[request responseString]; 
id usableResp = [response JSONFragmentValue]; 
1

您可以自己解析JSON數據,或者更好地使用類似TouchJSON的庫來爲您解析JSON數據。

+0

我認爲他/她已經在使用json框架。 – 2011-05-19 07:28:34

+0

@尼克韋弗,看起來你是對的。對你有+1耐心足以抵制指向罰款手冊。 :) – Caleb 2011-05-19 12:21:25