显示它我有这个网址:http://maps.google.com.br/maps/api/directions/json?origin=porto+alegre&destination=novo+hamburgo&sensor=false故障的解析JSON和UITableView的
而这种代码:
- (void)connectionDidFinishLoading:(NSURLConnection *)connection {
[connection release];
NSString *responseString = [[NSString alloc] initWithData:responseData encoding:NSUTF8StringEncoding];
[responseData release];
NSMutableDictionary *theDictionary = [responseString JSONValue];
NSLog(@"%@", theDictionary);
[responseString release];
if (theDictionary != nil)
{
NSArray *routesArray = [theDictionary objectForKey:@"routes"];
NSDictionary *firstRoute = [routesArray objectAtIndex:0];
NSArray *legsArray = [firstRoute objectForKey:@"legs"];
NSDictionary *firstLeg = [legsArray objectAtIndex:0];
steps = [firstLeg objectForKey:@"steps"];
}
[tableView reloadData];
}
我想显示每一个@在 “html_instructions” UITableView的。
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
// Return the number of rows in the section.
return [self.steps count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cachedCell"];
if (cell == nil)
cell = [[[UITableViewCell alloc]
initWithFrame:CGRectZero reuseIdentifier:@"cachedCell"] autorelease];
return cell;
}
缺少了什么在我的代码???应该是一些小细节...任何帮助将是伟大的!
'steps'是一个NSMutableArray?获取JSON数据吗?请清楚解释。 – Emon 2011-12-20 04:04:37
是的。 'steps'是nsmutablearray,json解析得很好(nslog)。 @Emon – libchief 2011-12-20 19:10:54