嗨朋友在我的項目中的數據來自JSONserialization
。其中某些數據收到html data
像這樣 <p>activity for m43 by c31</p>
我需要將此數據轉換爲nsstring
並顯示出來。我不知道如何轉換它,請提前幫助我。我已經通過一些解決方案,但不清楚。如何將HTML NSData轉換爲NSString?請幫助我提前致謝ios:如何將html數據轉換爲nsstring?
-(void)connectionDidFinishLoading:(NSURLConnection *)connection {
tweet = [[NSDictionary alloc]init];
tweet = [NSJSONSerialization JSONObjectWithData:webData options:kNilOptions error:nil];
[array1 addObject:[item objectForKey:@"activityTitle"]];//prints string data
[array2 addObject:[item objectForKey:@"activityType"]];//prints string data
[array3 addObject:[item objectForKey:@"id"]];//prints string data
[array4 addObject:[item objectForKey:@"sessionId"]];//prints string data
[array8 addObject:[item objectForKey:@"desc"]];// prints html data
NSLog(@"%@",array2);
NSString *str = [[NSString alloc] initWithData:webData encoding:NSUTF8StringEncoding];
NSLog(@"hiiiiiii",str);
}
我不知道如何將該數組8(包含html數據)轉換爲nsstring。我需要顯示它uitableviewcell。像這樣 - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString * simpleTableIdentifier = @「activismCell」; CAviewCELLCell * cell = [tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier forIndexPath:indexPath];
cell.activitytitle.text = (NSString *)[array1 objectAtIndex:indexPath.row];
cell.idline.text = (NSString *)[array3 objectAtIndex:indexPath.row];
cell.descline.text = (NSString *)[array8 objectAtIndex:indexPath.row];
cell.issuelabel.text = (NSString *)[array9 objectAtIndex:indexPath.row];
cell.timelabel.text = (NSString *)[array10 objectAtIndex:indexPath.row];
sessid = (NSString *)[array4 objectAtIndex:indexPath.row];
token = (NSString *)[array6 objectAtIndex:indexPath.row];
apikey = (NSString *)[array7 objectAtIndex:indexPath.row];
NSLog(@"%@,%@",sessid,token);
NSString *stat =(NSString *)[array2 objectAtIndex:indexPath.row];
NSLog(@"%@",stat);
NSString *trimmedString = [stat stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
if([trimmedString isEqualToString:@"Two Way Video Streaming"] || [trimmedString isEqualToString:@"One Way Video Streaming"]) {
[cell.startvideo setHidden:FALSE];
[cell.startvideo setImage:[UIImage imageNamed:@"ca_video.png"] forState:UIControlStateNormal];
[cell.startvideo addTarget:self action:@selector(playAction) forControlEvents:UIControlEventTouchUpInside];
}
else
[cell.startvideo setHidden:TRUE];
return cell;
}
NSJSONSerialization永遠不會創建一個NSData對象。所以,我想知道你在哪裏得到這個NSData對象。無論如何,如果你的html被嵌入到JSON中,它很可能已經被表示爲一個NSString。 – CouchDeveloper
請貼上你的代碼。這將有助於找出問題。我想你是從後端請求html數據。 – Pawan
我添加了我的代碼檢查它,並幫助我 – Naresh