我是 iPhone 开发者的初学者。我想显示来自我在源代码下面使用过的服务器的数据..
-(void)loadData:(id)sender
{
self.requestdata=[NSMutableData data];
NSURLRequest *request=[NSURLRequest requestWithURL:[NSURL URLWithString:kLatestKivaLoansURL]];
[[NSURLConnection alloc]initWithRequest:request delegate:self];
}
- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response
{
[requestdata setLength:0];
}
-(void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data
{
[requestdata appendData:data];
}
-(void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error
{
[connection release];
self.requestdata=nil;
}
#pragma mark-
#pragma process loan data
- (void)connectionDidFinishLoading:(NSURLConnection *)connection
{
[connection release];
NSString *responsedata=[[NSString alloc]initWithData:requestdata encoding:NSUTF8StringEncoding];
self.requestdata=nil;
NSDictionary *respDict = [[responsedata JSONValue]objectForKey:@"nodes"];
NSLog(@"Response Dict:%@",respDict);
NSMutableArray *arraY = [[NSMutableArray alloc]init];
arraY = [respDict mutableCopy];
NSLog(@"My array:%@",arraY);
NSString *mystr = [[[arraY objectAtIndex:0]valueForKey:@"node"]valueForKey:@"field_company_name_value"];
NSLog(@"Mystrname:%@",mystr);
NSArray *latestLoans=[(NSDictionary *)[responsedata JSONValue]objectForKey:@"responseData"];
NSLog(@"latest_dictionary:%@",latestLoans);
DisplayViewController *disp=[[DisplayViewController alloc]init];
for (int i = 0; i< [[latestLoans valueForKey:@"entries"] count] ; i++) {
// Search *aSearches = [[Search alloc] init];
NSDictionary *tempDict = [[latestLoans valueForKey:@"entries"] objectAtIndex:i];
// disp.link=[tempDict valueForKey:@"link"];
/*link = [tempDict valueForKey:@"link"];
aSearches.title = [tempDict valueForKey:@"title"];
aSearches.description = [tempDict valueForKey:@"contentSnippet"];
[appDelegate.search addObject:aSearches];*/
[appDelegate.disparray addObject:tempDict];
}
NSLog(@"DisplayArray:%@",appDelegate.disparray);
[self.view addSubview:disp.view];
/* DisplayViewController *disp=[[DisplayViewController alloc]initWithNibName:@"DisplayViewController" bundle:nil];
[self.navigationController pushViewController:disp animated:YES];*/
}
请提供适用于我的代码的任何建议或源代码