2013-11-21 3 views
0

json 데이터 (Jsp 서버)를 UITableviewcell에 표시하려고합니다. 의 I는 UITaleviewcell 세 UILables했다 제목 및 메시지와 시간 등의 데이터를 표시했다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"} 

내 JSON 데이터 아래에 다음과 같습니다. UILabel에서 메시지 데이터를 표시하는 방법에 대해서는 의문의 여지가 있습니다 (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

당신은있는 NSDictionary에 JSON 변환 JSONKit를 사용할 수 있습니다. 그런 다음 NSDictionary를 쿼리하여 필요한 문자열을 얻은 다음 NSString stringWithFormat:을 사용하여 문자열의 서식을 지정하고 형식이 지정된 문자열을 UILabel로 설정할 수 있습니다.

0

JSON 데이터는 각 사전에 '알림'사전 배열이있는 '결과'키가 있으며 각 사전에는 'title', 'message'및 'notification_created_time'키가있는 사전 배열입니다. .

당신의 테이블 뷰는 이러한 'notification'객체의 목록입니다. 따라서 NSJSONSerialization을 사용하여 JSON을 Foundation 객체로 변환 할 때 'notification'객체의 배열을 빌드해야합니다.

cellForRowAtIndexPath에서 indexPath.row를 사용하여이 배열에서 '알림'사전을 검색 한 다음이 사전의 값을 가져 와서 레이블을 채 웁니다.

관련 문제