JSON和TABLEVIEW钻取

时间:2013-09-11 05:26:21

标签: ios objective-c json uitableview

我有三个带导航控制器的uitableviews。每个tableview都由数组通过JSON填充。在mySQL表中我有类别,然后是City等项目,然后是城市的更多细节。用户可以选择城市并获取城市列表以及该城市的照片,但我希望当他们点击该城市时,他们应该能够看到更多信息,例如;这些城镇的名称,当他们点击城镇的任何名称时,应该为他们带来火车时间,公共汽车时间和出租车,这将进一步详细说明。

-(void)dataRetrieveMethod
{
    NSURL *url=[NSURL URLWithString:urlRetieval];
    NSData *data= [NSData dataWithContentsOfURL:url];

    json = [NSJSONSerialization JSONObjectWithData:data options:kNilOptions error:Nil];
    //instantiate arrays to hold data

    citiesArray=[[NSMutableArray alloc] init];

    for (int i=0; i<json.count; i++)
    {
        NSString *ids = [[json objectAtIndex:i] objectForKey:@"id"];
        NSString *cityName = [[json objectAtIndex:i] objectForKey:@"cityName"];



        City *myCity=[[City alloc] initWithCityID:ids CityName:cityName ];

        [citiesArray addObject:myCity];
    }

    [self.myTableView reloadData];


}

这给了我城市列表

我如何存储和检索城镇的名称,以便我可以拥有这样的东西

伦敦------- [[斯特拉特福德] [.......火车                            公交车......                            ......出租车]]         -------- [[Mile End] .......火车                            公交车......                            ......出租车]         --------- [[Leyton] .......火车                            公交车......                            ......出租车] picture here

1 个答案:

答案 0 :(得分:0)

    try it   use NSDictionary  under given  formate




      {
                milestones =             ( (2,3,4),(13,12));
                versions =             ((2,3,4),(13,12));
      },
  example
 NSArray *cities=[[NSArray alloc] initWithObjects:@"trins",@"buss",@"taxi" ,nil];
    NSDictionary *towensdict=[[NSDictionary alloc] initWithObjectsAndKeys:cities,@"stratford",cities,@"mile end",cities,@"leyton", nil];

    NSLog(@"cititedict:%@",towensdict);
    NSDictionary  *cities1=[[NSDictionary alloc] initWithObjectsAndKeys:towensdict,@"LONDON", nil];
    NSLog(@"cititedict:%@",cities1);