Currently i am working on an iOS app which requires me to parse the JSON data(announcements within our company) and show in a grouped tableview, i have already tried - stringByReplacingOccurrencesOfString and tried to show the links in UITextView but i am not getting the result i needed. I want to show only the data from the href tag which contains some links where users can click on them to see announcements. Below is the code i have written . Can anybody point me in the right direction ?
if (indexPath.section == 0) {
UILabel *issueStatus = [[UILabel alloc] initWithFrame:CGRectMake(10, 2, cell.frame.size.width, 15)];
[issueStatus setText:[[tmpArray objectAtIndex:indexPath.row] objectForKey:@"title"]];
issueStatus.textColor = [UIColor blackColor];
[cell.contentView addSubview:issueStatus];
UITextView *issueStatus2 = [[UITextView alloc] initWithFrame:CGRectMake(10, 20, cell.frame.size.width, 60)];
NSString *str1 = [[[[[[[tmpArray objectAtIndex:indexPath.row] objectForKey:@"body"] valueForKey:@"view"] valueForKey:@"value"] stringByReplacingOccurrencesOfString:@"<p>" withString:@""] stringByReplacingOccurrencesOfString:@"<a href=\"" withString:@"" ] stringByReplacingOccurrencesOfString:@"class=external-link rel=nofollow>" withString:@""];
[issueStatus2 setText:str1];
issueStatus2.editable = NO;
issueStatus2.scrollEnabled = NO;
issueStatus2.dataDetectorTypes = UIDataDetectorTypeLink;
[cell.contentView addSubview:issueStatus2];
and below is the sample JSON data for a key-value pair i am getting out of JSON , Can any one help me on how to get only the link in the href tag to be displayed in my UITextView?
{
id: "14975323",
type: "page",
status: "current",
title: "How to Re-Open a Resolved Ticket",
body: {
view: {
value: "<p><a href="https://drive.google.com/a/domain.com/file/d/0B9TSHFNjUGsjYmV2a3pzcTFOWXM/edit" class="external-link" rel="nofollow">https://drive.google.com/a/domain.com/file/d/0B9TSHFNjUGsjYmV2a3pzcTFOWXM/edit</a></p>",
representation: "view",
_expandable: {
content: "/rest/api/content/14975323"
}
}
_expandable: {
editor: "",
export_view: "",
anonymous_export_view: "",
storage: ""
}
}
0 comments:
Post a Comment