2
我想解析使用JSON解析器和结果,我得到我必须把它放到表视图。我已经传递了一个常量键值和一个字符串。JSON解析器输出显示在tableview
是否存在解析步骤错误?或错过了。
我已经包含了JSON解析器的代码。
在此先感谢。
SBJSON *parser = [[SBJSON alloc] init];
NSString *urlString =[NSString stringWithFormat:@"http://api.shopwiki.com/api/search?key=%@&q=%@",apiKey, string];
NSURL *url = [NSURL URLWithString:urlString];
NSURLRequest *request = [[NSURLRequest alloc] initWithURL: url];
NSData *response = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:nil];
NSString *json_string = [[NSString alloc] initWithData:response encoding:NSUTF8StringEncoding];
NSMutableArray *statuses = [[NSMutableArray alloc]init];
statuses = [parser objectWithString:json_string error:nil];
NSLog(@"Array Contents: %@", statuses);
NSMutableArray *statuses0 = [[NSMutableArray alloc]init];
statuses0 = [statuses valueForKey:@"offers"];
NSLog(@"Array Contents: %@", statuses0);
//For Title
NSMutableArray *statuses1 = [[NSMutableArray alloc]init];
statuses1 = [[[statuses valueForKey:@"offers"] valueForKey:@"offer"]valueForKey:@"title"];
NSLog(@"Array Contents 4 Title: %@", statuses1);
在这里,在statuses1阵列我得到20个对象里面全是冠军,现在我只是想显示的标题为实现代码如下: -
的实现代码如下代码片段: -
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
NSLog(@"status count:%d",[statuses1 count]);
return [statuses1 count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
NSLog(@"Inside Tableview");
int counter=indexPath.row;
NSString *CellIdentifier = [NSString stringWithFormat:@"%d",counter];
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil)
{
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
cell.selectionStyle=UITableViewCellSelectionStyleNone;
}
NSLog(@"Inside Tableview 1");
cell.textLabel.text=[statuses1 objectAtIndex:indexPath.row];
NSLog(@"Inside Tableview 2");
return cell;
}
我得到不好的超额异常,它击中: -
cell.textLabel.text=[statuses1 objectAtIndex:indexPath.row];
请给我解决方案 在此先感谢: -
这是一样的http://stackoverflow.com/questions/3461494/json-parsing-error 几个编辑? – 2010-08-12 16:05:56
是的,但我已经编辑了它的一些部分.. – 2010-08-12 16:11:03