我是iPhone開發者的初學者。我想顯示從下面的源代碼我已經使用服務器數據..如何在ios中使用json解析獲取數據
-(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];*/
}
請給任何建議或源代碼,這是適用於我的代碼
請問,你可以把更多的可讀代碼? – RFG
首先向我們解釋它的功能。如果你不能解釋它,*你在做什麼使用它?* –
你對這個源代碼有什麼問題需要幫助? –