简体   繁体   English

如何在UILabel中显示html数据

[英]how to display html data in UILabel

I want to display json data(Jsp server) in my UITableviewcell. 我想在我的UITableviewcell中显示json数据(Jsp服务器)。 The following below is my json data 以下是我的json数据

[{"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"}

I had took three UILables in UITaleviewcell and display the data like title and message and time. 我在UITaleviewcell中使用了三个UILable,并显示了诸如标题,消息和时间之类的数据。 I have small doubt how to display message data(your reqeust  PAD_0000896 is In-Process) in UILabel. 我毫不怀疑如何在UILabel中显示消息数据(您的要求PAD_0000896正在处理中)。 the message data is like html tag.i had no idea how to display the html data in UILabel.i am having idea how to display title and time in uilabel. 消息数据就像html标签。我不知道如何在UILabel中显示html数据。我不知道如何在uilabel中显示标题和时间。

This is my code. 这是我的代码。

jsondata.m 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 *identifier=@"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;

}

You can use JSONKit to convert the json to NSDictionary. 您可以使用JSONKit将json转换为NSDictionary。 And then you can query NSDictionary to get the required string and then use NSString stringWithFormat: to format the string and set the formatted string to the UILabel. 然后,您可以查询NSDictionary以获取所需的字符串,然后使用NSString stringWithFormat:格式化字符串并将格式化后的字符串设置为UILabel。

Your JSON data is an array of dictionaries, where each dictionary has a key of 'result' that has an array of 'notification' dictionaries, where each dictionary has the keys 'title', 'message' and 'notification_created_time'. 您的JSON数据是一个字典数组,其中每个字典都有一个“结果”键,该键具有一个“通知”字典数组,其中每个字典都有键“ title”,“ message”和“ notification_created_time”。

your table view is a list of these 'notification' objects so when you convert the JSON to Foundation objects using NSJSONSerialization you build an array of 'notification' objects; 您的表格视图是这些“通知”对象的列表,因此当您使用NSJSONSerialization将JSON转换为Foundation对象时,会构建一个“通知”对象的数组;

for each cell, in cellForRowAtIndexPath, you retrieve the 'notification' dictionary from this array using the indexPath.row and then get at the values from this dictionary to populate your labels. 对于每个单元格,在cellForRowAtIndexPath中,您可以使用indexPath.row从此数组中检索“通知”字典,然后从该字典中获取值以填充标签。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM