Pandey_Laxman
Pandey_Laxman

Reputation: 3908

how to convert html entity in to nsstring?

I am getting nested json data from webservices then displaying in UILabel inside a UITableView's Cell. The problem is that data comes in html entity that is like

"Headline Description" = "ephox,パーカーで働くことは、単なる仕事ではam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci tation \t\t\t\tullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat. Duis autem vel eum \t\t\t\tiriure dolor in hendrerit in vulputate velit esse molestie consequat

"Headline Description" = "ephox,&#12497&#12540&#12459t (here is the actual html entity removing semicolon ; because browser converts it automatically in char as above you see in headline desciption)

I need my uilabel to convert like above , UIWebview coverting it but not uilabel,

could anyone please suggest me the way to covert html entity to char like above in bold.

thanks you so much in advance

Upvotes: 1

Views: 1231

Answers (1)

Pandey_Laxman
Pandey_Laxman

Reputation: 3908

Finally I found the answer myself posting it here so that someone can get help from here in future.

if (iOS7Version)
        {
            NSData *stringData = [str dataUsingEncoding:NSUTF8StringEncoding];

        NSDictionary *options = @{NSDocumentTypeDocumentAttribute:NSHTMLTextDocumentType};
        NSAttributedString *decodedString;
        decodedString = [[NSAttributedString alloc] initWithData:stringData
                                                         options:options
                                              documentAttributes:NULL
                                                           error:NULL];
        lbl.text=decodedString.string;
    }
    else
        lbl.text=str;

Upvotes: 1

Related Questions