2011-05-16 7 views
1

저는 iPhone 앱 개발에 새로운 사람입니다. 도움이 필요합니다 ... 일부 데이터 (은행 이름)를 구문 분석하여 UITableView에 표시하고 싶습니다.iPhone JSON 구문 분석

 NSArray *atmDAta = [responseString JSONValue]; 
for (NSDictionary *dict in atmDAta) { 
    NSLog(@"%@", [dict objectForKey:@"Name"]); 
    [listOfItems addObject:[dict objectForKey:@"Name"]]; 
} 

을하지만이 같은 테이블에 그들을 표시 할 때 :

cell.textLabel.text = [listOfItems objectAtIndex:indexPath.row]; 
return cell; 

이 나에게 아무런 표시되지 않습니다 나는 JSON 형식에 은행 이름을 구문 분석이 코드를 사용하고 있습니다 테이블하지만 NSlog가 작동하고 xcode 로그에 은행 이름이 표시됩니다. 도와주세요.

+0

코드의 당신이 좀 더 수 있을까? ListOfItem이 올바르게 유지됩니까? 당신이 파싱을 마쳤을 때 그것에 어떤 항목이 있습니까? 또는 빈 문자열을 삽입하는 이름입니까? – rckoenes

+0

'code' NSMutableArray * listOfItems; – Rocky

+0

Yaeh 내가 올바르게 유지했습니다. – Rocky

답변

0

전화 [yourtable reloadData]; 당신이

+0

그래, 내가 이렇게해도 [atmList reloadData]; 하지만 여전히 출력이 없습니다 – Rocky

+0

더 많은 코드를 게시하거나 JSON을 얻을 수있는 링크를 붙여 넣을 수 있습니까 –

+0

이것은 [link] (http://www.fourspan.com/atminfo/getatminfo.php?lang=47.822828)입니다. & long = -28.44989) 어디에 내가 데이터를 구문 분석 – Rocky

0

당신이 JSON 구문 분석에서 최신 크리켓 점수를 얻을 것이다이 코드에서 JSON 구문 분석

-(void)getLatestScore 
{ 
    SBJsonParser *parser = [[SBJsonParser alloc] init];  

    NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"http://json-cricket.appspot.com/score.json"]]; 

    // Perform request and get JSON back as a NSData object 
    NSData *response = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:nil]; 

    // Get JSON as a NSString from NSData response 
    NSString *str_Json_String = [[NSString alloc] initWithData:response encoding:NSUTF8StringEncoding]; 

    // parse the JSON response into an object 

    NSDictionary *dicCricketScore = [parser objectWithString:str_Json_String error:nil]; 

    lblDate.text = [dicCricketScore objectForKey:@"date"]; 
    lblMatch.text = [dicCricketScore objectForKey:@"match"]; 
    lblBattingTeam.text = [dicCricketScore objectForKey:@"batting_team"]; 
    lblScore.text = [dicCricketScore objectForKey:@"score"]; 
    lblSummary.text = [dicCricketScore objectForKey:@"summary"]; 
} 

이 코드를 참조하십시오 구문 분석 JSON ....

+0

안녕 Mehul Mistry ...... 많은 forX이 있지만 이미 레이블에 데이터를 구문 ... .... 이제는 데이터를 구문 분석 할 필요가 그것을 UITableView – Rocky

+0

에 표시하십시오. 어디에서 데이터를 저장합니까? NSMutableArray 또는 anyother ... –

0

를 완료 할 때 @ Rocky 시도해보기

선언 .h NSArray * listOfItems;

NSMutableArray *tempArray = [[NSmutableArray alloc]initWithCapacity:[atmDAta count]]; 
for (NSDictionary *dict in atmDAta) { 
    NSLog(@"%@", [dict objectForKey:@"Name"]); 
    if (![dict valueForKeyIsNull:@"Name"]) { 
     [tempArray addObject:[dict objectForKey:@"Name"]];   
    } 
} 
self.listOfItems = [NSArray arrayWithArray:tempArray]; 
[tempArray release]; 
if([self.listOfItems count] > 0) 
[yourTable reloadData]; 

하는 .m

에서

@property (nonatomic, copy)NSArray *listOfItems; 

이를 사용 나는 종류

@implementation NSDictionary (KeyExists) 

- (BOOL) keyExists:(NSString *) key { 
    return [self valueForKey:key] != nil; 
} 

- (BOOL) valueForKeyIsNull:(NSString *) key { 
    return ![self keyExists:key] || ((NSNull *)[self valueForKey:key] == [NSNull null]); 
} 
@end 

건배를 사용하고 있습니다!

0

당신이 할 수있는 배열을 추가 한 후 [LISTOFITEMS은 유지]