JSON iOS parsing string
{"response":[33689822,64091979,69682048,74160161]}
-
- (void)requestCompleted:(ASIHTTPRequest *)request
{
NSString *responseString = [request responseString];
NSLog(@"okRequest|| %@",responseString);
SBJSON *parser = [[SBJSON alloc] init];
// Prepare URL request to downl开发者_如何学Coad 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"
}
}
How I can get array of numbers in "response"? (33689822,64091979,69682048,74160161)
Try this:
for (NSNumber *number in [statuses objectForKey:@"response"]) {
NSLog(@"%@", number);
}
You can either parse the JSON data yourself, or better, use a library like TouchJSON to do it for you.
Try using JSONFragmentValue directly.
NSString *response=[request responseString];
id usableResp = [response JSONFragmentValue];
精彩评论