임 말한다 내 코드, 그 반환 오류에 문제가 ...아이폰 JSON의 TableView에
2011-12-24 22 : 52 : 36.280 BusinessManager [479 : 20B]에 의한 * 종료 애플 리케이션 캐치되지 않는 예외 'NSInvalidArgumentException'이유로 -
,617 :> 여기서#import "BusinessManagerAppDelegate.h" #import "ProspectViewController.h" #import "JSON.h" @implementation ProspectViewController @synthesize jsonArray; - (void)viewDidLoad { NSURL *jsonURL = [NSURL URLWithString:@"https://www.mysite.php"]; NSString *jsonData = [[NSString alloc] initWithContentsOfURL:jsonURL]; NSLog(jsonData); self.jsonArray = [jsonData JSONValue]; [jsonURL release]; [jsonData release]; } - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { return 1; } - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return [jsonArray count]; } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *Prospects = @"agencyname"; UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:Prospects]; if (cell == nil) { cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:Prospects] autorelease]; } cell.text = (NSString *)[self.jsonArray objectAtIndex:indexPath.row]; return cell; } - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { } - (void)viewWillAppear:(BOOL)animated { [super viewWillAppear:animated]; } - (void)viewDidAppear:(BOOL)animated { [super viewDidAppear:animated]; } - (void)viewWillDisappear:(BOOL)animated { } - (void)viewDidDisappear:(BOOL)animated { } - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { return (interfaceOrientation == UIInterfaceOrientationPortrait); } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; } - (void)dealloc { [jsonArray dealloc]; [super dealloc]; } @end
'* [NSCFDictionary isEqualToString는 :] 미정 선택기 인스턴스 0x3e965e0 전송'은 코드
메신저 나는 모든 것이 올바르게 설정되어 있고 JSON이 콘솔에서 올바르게 반환되고 있음을 확신합니다.
NSDictionary JSON과 NSArray JSON 사이의 차이점을 알지 못합니다. 여기에 JSON [{ "0": "Test Agency", "agencyname" : "Test Agency"}, { "0": "Test Agency", "agencyname": "Test Agency"}] – savagenoob
JSON을 파싱 할 때 Objective-C로 변환합니다. 이것은 NSDictionary 나 NSArray 중 하나 일 수 있습니다. NSDictionaries에 대한 자세한 내용은 http://developer.apple.com/library/ios/#documentation/Cocoa/Reference/Foundation/Classes/NSDictionary_Class/Reference/Reference.html을 참조하십시오. 기본적으로, 당신은 그것을'NSDictionary * infoDictionary = [self.jsonArray objectAtIndex : indexPath.row]'로 변경하기를 원할 것입니다. 그런 다음'cell.text = [infoDictionary objectForKey : @ "agencyname"]'을 수행하십시오. NSDictionary는 "키"와 "값"("에이전시 이름"-> "테스트 에이전시" – Louis
당신을 사랑합니다. 이것을 하루 종일 알아 내려고 노력하는 것들을 저장하는 방법입니다. – savagenoob