i have the following JSON Data, which is a respond from my Webservice.
{"d": [{"raumKlassenObject":"Telepresenzraum"},
{"raumKlassenObject":"Besprechungsraum"},
{"raumKlassenObject":"Videokonferenzraum"},
{"raumKlassenObject":"IT-Schulungsraum"},
{"raumKlassenObject":"Konferenzraum"}]}
How can i display the Data Telepresenzraum, Besprechungsraum etc… in a TableView.
Heres my Code so far.
- (void)viewDidLoad
{
[super viewDidLoad];
dic = [NSJSONSerialization JSONObjectWithData:result options:kNilOptions error:nil];
array = [dic allKeys];
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
// Return the number of sections.
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
// Return the number of rows in the section.
return array.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
cell.textLabel.text=[NSString stringWithFormat:@"%@",[dic objectForKey:@"d"]];
return cell;
}
If i do it like that the output in the Tableview is
[{"raumKlassenObject":"Telepresenzraum"},{"raumKlassenObject":"Besprechungsraum"},{"raumKlassenObject":"Videokonferenzraum"},{"raumKlassenObject":"IT-Schulungsraum"},{"raumKlassenObject":"Konferenzraum"}]
I dont know how to display only Telepresenzraum, Besprechungsraum, Videokonferenzraum etc.. in tableview rows.
Thx for help.
You top level dictionary only has one key,”d”, so array.count will be 1 and the [dic objectForKey:@”d”] will be the whole array of dictionaries.
So, to fix this redefine array as:
This should give you an array of all the values for that key. Then, replace the first line below with the second: