【发布时间】:2011-12-25 07:05:30
【问题描述】:
我的代码有问题,它返回一个错误,上面写着...
2011-12-24 22:52:36.280 BusinessManager[479:20b] * 由于未捕获的异常“NSInvalidArgumentException”而终止应用程序,原因:“* -[NSCFDictionary isEqualToString:]:无法识别的选择器发送到实例 0x3e965e0'>
代码如下:
#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
我很确定我已经正确设置了所有内容,并且 JSON 在控制台中正确返回。
【问题讨论】:
标签: objective-c json cocoa-touch iphone-sdk-3.0