显示服务输出的问题 Objective-C
Issue with displaying the output from a service Objective-C
下面是我从服务中获取的数组。
{
ClassDays = "Monday,Tuesday,Wednesday,Thursday,Friday,Saturday";
empName = Abhinav;
Experience = "4 Years";
Attendance = Daily;
Subject = Physics;
ClassTimings = (
{
GMT = "PLUS05:30";
Time = "12:50:00";
TimeZone = "Asia/Hyderabad";
},
{
GMT = "PLUS05:30";
Time = "13:00:00";
TimeZone = "Asia/Hyderabad";
},
{
GMT = "PLUS05:30";
Time = "13:10:00";
TimeZone = "Asia/Hyderabad";
},
{
GMT = "PLUS05:30";
Time = "13:20:00";
TimeZone = "Asia/Hyderabad";
}
);
JoinedDate = "2017-003-06";
Education = M.Tech;
empId = 535;
}
我的问题是上面的数组输出能够显示 empName、Experience、Attendance、Subject 和 Education 的值,但无法显示 ClassTimings GMT、Time、TimeZone。我如何从下面的数组中显示 ClassTimings。下面是我试过的代码。请帮我找出问题所在。 TIA
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil)
{
//Some code
}
NSArray *keys = [empDict allKeys];
for(int i=0 ; i<[keys count]; i++ )
{
NSString *value=[medicationDict objectForKey:[keys objectAtIndex:i]];
if ([value isEqual: [NSNull null]]) {
[empDict setValue:@"--" forKey:[keys objectAtIndex:i]];
}
}
if(indexPath.row==0)
{
cell.textLabel.text = @"EmployeeName";
cell.detailTextLabel.text=[empDict objectForKey:@"empName"];
}
if(indexPath.row==1)
{
cell.textLabel.text = @"Experience";
cell.detailTextLabel.text=[empDict objectForKey:@"Experience"];
}
if(indexPath.row==2)
{
cell.textLabel.text = @"Attendance";
cell.detailTextLabel.text=[empDict objectForKey:@"Attendance"];
}
if(indexPath.row==3)
{
cell.textLabel.text = @"Subject";
cell.detailTextLabel.text=[empDict objectForKey:@"Subject"];
}
if(indexPath.row==4)
{
cell.textLabel.text = @"Education";
cell.detailTextLabel.text=[empDict objectForKey:@"Education"];
}
if(indexPath.row==5)
{
cell.textLabel.text = @"ClassTimings";
cell.detailTextLabel.text=[empDict objectForKey:@"GMT",
@"Time",@"TimeZone"];
}
}
简单您可以从 Json 获取数组并传入 tableview 索引路径行因为 ClassTimings 正在从您的 JsonDictionary
创建数组
如果只显示Only single row
if(index path.row ==5)
{
NSString *stgmt = [empDict objectForKey:@"GMT"];;
NSString *strtime = [empDict objectForKey:@"Time"];;
NSString *strtimeZone = [empDict objectForKey:@"TimeZone"];
}
// 如果你想制作数组并显示每个表视图行而不是它的逻辑
yourArray = [jsonDict objectForKey:@"ClassTimings"];
NSString *stgmt = [yourArray objectAtIndex:indexPath.row]objectForKey:@"GMT"];;
NSString *strtime = [yourArray objectAtIndex:indexPath.row]objectForKey:@"Time"];;
NSString *strtimeZone = [yourArray objectAtIndex:indexPath.row]objectForKey:@"TimeZone"];;
下面是我从服务中获取的数组。
{
ClassDays = "Monday,Tuesday,Wednesday,Thursday,Friday,Saturday";
empName = Abhinav;
Experience = "4 Years";
Attendance = Daily;
Subject = Physics;
ClassTimings = (
{
GMT = "PLUS05:30";
Time = "12:50:00";
TimeZone = "Asia/Hyderabad";
},
{
GMT = "PLUS05:30";
Time = "13:00:00";
TimeZone = "Asia/Hyderabad";
},
{
GMT = "PLUS05:30";
Time = "13:10:00";
TimeZone = "Asia/Hyderabad";
},
{
GMT = "PLUS05:30";
Time = "13:20:00";
TimeZone = "Asia/Hyderabad";
}
);
JoinedDate = "2017-003-06";
Education = M.Tech;
empId = 535;
}
我的问题是上面的数组输出能够显示 empName、Experience、Attendance、Subject 和 Education 的值,但无法显示 ClassTimings GMT、Time、TimeZone。我如何从下面的数组中显示 ClassTimings。下面是我试过的代码。请帮我找出问题所在。 TIA
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil)
{
//Some code
}
NSArray *keys = [empDict allKeys];
for(int i=0 ; i<[keys count]; i++ )
{
NSString *value=[medicationDict objectForKey:[keys objectAtIndex:i]];
if ([value isEqual: [NSNull null]]) {
[empDict setValue:@"--" forKey:[keys objectAtIndex:i]];
}
}
if(indexPath.row==0)
{
cell.textLabel.text = @"EmployeeName";
cell.detailTextLabel.text=[empDict objectForKey:@"empName"];
}
if(indexPath.row==1)
{
cell.textLabel.text = @"Experience";
cell.detailTextLabel.text=[empDict objectForKey:@"Experience"];
}
if(indexPath.row==2)
{
cell.textLabel.text = @"Attendance";
cell.detailTextLabel.text=[empDict objectForKey:@"Attendance"];
}
if(indexPath.row==3)
{
cell.textLabel.text = @"Subject";
cell.detailTextLabel.text=[empDict objectForKey:@"Subject"];
}
if(indexPath.row==4)
{
cell.textLabel.text = @"Education";
cell.detailTextLabel.text=[empDict objectForKey:@"Education"];
}
if(indexPath.row==5)
{
cell.textLabel.text = @"ClassTimings";
cell.detailTextLabel.text=[empDict objectForKey:@"GMT",
@"Time",@"TimeZone"];
}
}
简单您可以从 Json 获取数组并传入 tableview 索引路径行因为 ClassTimings 正在从您的 JsonDictionary
创建数组如果只显示Only single row
if(index path.row ==5)
{
NSString *stgmt = [empDict objectForKey:@"GMT"];;
NSString *strtime = [empDict objectForKey:@"Time"];;
NSString *strtimeZone = [empDict objectForKey:@"TimeZone"];
}
// 如果你想制作数组并显示每个表视图行而不是它的逻辑
yourArray = [jsonDict objectForKey:@"ClassTimings"];
NSString *stgmt = [yourArray objectAtIndex:indexPath.row]objectForKey:@"GMT"];;
NSString *strtime = [yourArray objectAtIndex:indexPath.row]objectForKey:@"Time"];;
NSString *strtimeZone = [yourArray objectAtIndex:indexPath.row]objectForKey:@"TimeZone"];;