开发者

JSON iOS parsing string

开发者 https://www.devze.com 2023-03-07 10:26 出处:网络
{\"response\":[33689822,64091979,69682048,74160161]} - - (void)requestCompleted:(ASIHTTPRequest *)request
{"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];
0

精彩评论

暂无评论...
验证码 换一张
取 消