0
#pragma mark -
#pragma mark Fetch loans from internet

-(void)loadData
{
    self.responseData = [NSMutableData data];

    NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:
                                                          @"http://192.168.1.104:8080/Test/ItemGroup.jsp"]];
    [[NSURLConnection alloc] initWithRequest:request delegate:self];
}

- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response {
    [responseData setLength:0];
}

- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data {
    [responseData appendData:data];
}

- (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error {
    [connection release];
    self.responseData = nil;
}

#pragma mark -
#pragma mark Process loan data
- (void)connectionDidFinishLoading:(NSURLConnection *)connection {
    [connection release];

    NSString *responseString = [[NSString alloc] initWithData:responseData encoding:NSUTF8StringEncoding];
    self.responseData = nil;


    array=[responseString JSONValue];
    NSMutableString *text=[NSMutableString stringWithString:@"Values:\n"];
    for (int i=0; i <[array count]; i++) {
        [text appendFormat:@"%@\n",[array objectAtIndex:i]];

        // NSLog(@"Values:""%@\n",array);

    }

}
4

1 回答 1

0

您可以使用RestKit(一个 Cocoa RESTful Web 服务框架)来获取数据并使用对象映射功能将返回的数据映射到对象数组。

RESTKit Object Mapping wiki 中给出的示例将 JSON 文档映射到 Article 实例数组中:https ://github.com/RestKit/RestKit/wiki/Object-mapping

于 2012-05-18T05:06:06.197 回答