html字符串解码,好

/**
&#XXX转中文

@param contentStr &#XXX字符串
@return utf8编码字符串
/
-(NSString
)htmlStrDecodeWithContent:(NSString*)contentStr
{
NSData *data = [contentStr dataUsingEncoding:NSUTF8StringEncoding];
NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:nil];
NSString *content = dic[@"content"];
NSAttributedString * contentAttrStr = [[NSAttributedString alloc] initWithData:[content dataUsingEncoding:NSUnicodeStringEncoding] options:@{ NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType } documentAttributes:nil error:nil];
NSMutableDictionary *muDic=[[NSMutableDictionary alloc] initWithDictionary:dic];
[muDic setObject:[contentAttrStr string] forKey:@"content"];

NSData *contentData=[NSJSONSerialization dataWithJSONObject:muDic
options:NSJSONWritingPrettyPrinted
error:nil];
return [[NSString alloc] initWithData:contentData encoding:NSUTF8StringEncoding];
}

你可能感兴趣的:(html字符串解码,好)