顯示它我有這個網址: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