Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/71.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Html 是否将attributetext转换为UTF8字符串?_Html_Ios_Objective C - Fatal编程技术网

Html 是否将attributetext转换为UTF8字符串?

Html 是否将attributetext转换为UTF8字符串?,html,ios,objective-c,Html,Ios,Objective C,我正在从服务器获取\Ud835\Udc13\Ud835\Udc1e\Ud835\Udc2c\Ud835\Udc2d字符串 当我使用NSMutableAttributeString转换时 NSMutableAttributedString *attribute = [[NSMutableAttributedString alloc] initWithData:[self.message dataUsingEncoding:NSUTF8StringEncoding] options:@{NSDoc

我正在从服务器获取
\Ud835\Udc13\Ud835\Udc1e\Ud835\Udc2c\Ud835\Udc2d
字符串

当我使用NSMutableAttributeString转换时

 NSMutableAttributedString *attribute = [[NSMutableAttributedString alloc] initWithData:[self.message dataUsingEncoding:NSUTF8StringEncoding] options:@{NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType, NSCharacterEncodingDocumentAttribute: [NSNumber numberWithInt:NSUTF8StringEncoding]} documentAttributes:nil error:nil];
它以属性字符串的形式在标签上显示完美的测试

我想使用UITexView将测试发送到服务器

我正在使用以下代码

NSDictionary *documentAttributes = @{NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType, NSCharacterEncodingDocumentAttribute: [NSNumber numberWithInt:NSUTF8StringEncoding]};
    NSData *htmlData = [txtView.internalTextView.attributedText dataFromRange:NSMakeRange(0, txtView.internalTextView.attributedText.length) documentAttributes:documentAttributes error:NULL];
    NSString *htmlString = [[NSString alloc] initWithData:htmlData encoding:NSUTF8StringEncoding];
它打印HTML

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta http-equiv="Content-Style-Type" content="text/css">
<title></title>
<meta name="Generator" content="Cocoa HTML Writer">
<style type="text/css">
p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 16.0px '.SF UI Text'}
span.s1 {font-family: '.SFUIText'; font-weight: normal; font-style: normal; font-size: 16.00pt}
</style>
</head>
<body>
<p class="p1"><span class="s1">Test</span></p>
</body>
</html>

p、 p1{页边距:0.0px 0.0px 0.0px 0.0px;字体:16.0px'.SF UI Text'}
span.s1{font-family:'.SFUIText';字体大小:正常;字体样式:正常;字体大小:16.00pt}

测试

这是错误的,它应该只显示测试。我怎样才能做到这一点

-(NSMutableAttributedString*)getHtmlColorStringForCustomStyle:(NSString*)customString withBold:(NSString*)boldString italic:(NSString*)italicString andUnderLine:(NSString*)underlineString withColor:(NSString*)color
{

NSMutableAttributedString*attStringforCustomStyle=[[NSMutableAttributedString alloc]initWithData:[customString dataUsingEncoding:NSUTF8StringEncoding]选项:@{NSDocumentTypeDocumentAttribute:NSHTMLTextDocumentType

}文档属性:无错误:无]

[attStringforCustomStyle beginEditing];

[attStringforCustomStyle addAttribute:NSForegroundColorAttributeName value:[UIColor colorwithHexString:color alpha:1.0] range:NSMakeRange(0,customString.length)];

if ([boldString isEqualToString:@"yes"])
{
    [attStringforCustomStyle addAttribute:NSFontAttributeName
                                    value:[UIFont boldSystemFontOfSize:12]
                                    range:NSMakeRange(0, attStringforCustomStyle.length)];
}

if ([italicString isEqualToString:@"yes"]) //Put in else if because it does not apply both in single string
{

    [attStringforCustomStyle addAttribute:NSFontAttributeName
                                    value:[UIFont italicSystemFontOfSize:12]
                                    range:NSMakeRange(0, attStringforCustomStyle.length)];
}

if ([underlineString isEqualToString:@"yes"])
{

    [attStringforCustomStyle addAttribute:NSUnderlineStyleAttributeName
                                    value:@(NSUnderlineStyleSingle)
                                    range:NSMakeRange(0, attStringforCustomStyle.length)];
}


[attStringforCustomStyle endEditing];

return attStringforCustomStyle;

}

引用中不是HTML,而是CSS。CSS用于格式化HTML,但它不是HTML。@D.Pardal请检查更新的问题。我认为这可能是因为HTML代码开头的
字符。没有问题。输出在Chrome中工作。您使用的浏览器/程序是什么?