I have a page that takes in a zip code from a user, sends that data to a php page, then retrieves the data via JSON. This page is throwing an error that says:
2011-12-27 15:17:49.919 BusinessManager[3595:20b] * Terminating app due to uncaught exception ‘NSInvalidArgumentException’, reason: ‘* -[NSConcreteData isFileURL]: unrecognized selector sent to instance 0x4751490′
The code is:
- (id)initWithNibName:(NSString *)SearchZip bundle:(NSBundle *)nibBundleOrNil {
if (self = [super initWithNibName:SearchZip bundle:nibBundleOrNil]) {
// Custom initialization
}
return self;
}
- (IBAction) searchzip: (id) sender
{
NSString *post =[NSString stringWithFormat:@"zipcode=%@",zipField.text];
NSString *hostStr = @"https://www.mysite.com/searchzip.php?";
hostStr = [hostStr stringByAppendingString:post];
NSData *dataURL = [NSData dataWithContentsOfURL: [ NSURL URLWithString: hostStr ]];
NSString *jsonData = [[NSString alloc] initWithContentsOfURL:dataURL];
self.zipArray = [jsonData JSONValue];
[jsonData release];
}
- (void)viewDidLoad {
[super viewDidLoad];
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return [zipArray count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath: (NSIndexPath *)indexPath {
NSDictionary *infoDictionary = [self.zipArray objectAtIndex:indexPath.row];
static NSString *Prospects = @"agencyname";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:Prospects];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:Prospects] autorelease];
}
// setting the text
cell.text = [infoDictionary objectForKey:@"agencyname"];
self.navigationItem.title = @"Zip Search";
// Set up the cell
return cell;
}
You’re attempting to pass an instance of
NSDatainto-initWithContentsOfURL:to create thejsonDatainstance ofNSString.I’m about to pimp your method. Notice that I’ve removed creating an
NSDataobject altogether and renamed variables to be more clear.