2013-11-21 44 views
0

我想在我的UITableviewcell中显示json数据(Jsp服务器)。下面以下是我的JSON数据如何在UILabel中显示html数据

[{"result":[{"notification_id":106,"title":"Service Request","message":"your reqeust  PAD_0000882 is In-Process","notification_created_time":"Nov18,13"},{"notification_id":158,"title":"Service Request","message":"your reqeust  PAD_0000896 is In-Process","notification_created_time":"Nov19,13"} 

我已经花了三年UILables在UITaleviewcell并显示类似的标题和消息和时间数据。我很怀疑如何在UILabel中显示消息数据(您的reqeust PAD_0000896在进程中)。消息数据就像html tag.i不知道如何在UILabel.i中显示html数据我有想法如何在uilabel中显示标题和时间。

这是我的代码。

jsondata.m

NSArray *arrResults = [dict1 valueForKey:@"result"]; 

listOfObjects = [NSMutableArray array]; 


for (NSDictionary *dictRes in arrResults) 

{ 


for (NSDictionary *dictResSub in dictRes) 

{ 

Attributes *at = [[Attributes alloc] init]; 


at.message = [dictResSub valueForKey:@"message"]; 


[listOfObjects addObject:at]; 

} 

} 

[tableVwTotalRequests reloadData]; 

} 


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 

{ 

static NSString *[email protected]"cell"; 

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier]; 

if (cell == nil) 

{ 

cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"identifier"]; 

} 


UIView *myBackView = [[UIView alloc] initWithFrame:cell.frame]; 

myBackView.backgroundColor = [UIColor colorWithRed:0.325490196 green:0.3960784 blue:0.90196078 alpha:1]; 

cell.selectedBackgroundView = myBackView; 




UILabel *lblDesc=[[UILabel alloc]initWithFrame:CGRectMake(10, 22, 100, 20)]; 

lblDesc.highlightedTextColor=[UIColor whiteColor]; 

lblDesc.font=[UIFont systemFontOfSize:12.0]; 

[cell.contentView addSubview:lblDesc]; 


Attributes *att = [listOfObjects objectAtIndex:indexPath.row]; 


strRequestId=att.requestId; 



lblDesc.text=att.message; 




return cell; 

} 
+0

你在寻找HTML转换为纯文本吗? – manujmv

回答

0

您可以使用JSONKit到JSON转换为NSDictionary的。然后,您可以查询NSDictionary获取所需的字符串,然后使用NSString stringWithFormat:格式化字符串并将格式化的字符串设置为UILabel。

0

您的JSON数据是一个字典数组,其中每个字典都有一个'result'键,它有一个'notification'字典数组,其中每个字典都有'title','message'和'notification_created_time' 。

您的表视图是这些'通知'对象的列表,因此当您使用NSJSONSerialization将JSON转换为Foundation对象时,您将构建'通知'对象的数组;

对于每个单元格,在cellForRowAtIndexPath中,使用indexPath.row从此数组中检索'notification'字典,然后获取此字典中的值以填充标签。