2016-09-21 2 views
2

に中国のHTML文字列を変換する方法機能の下に使用していますNSStringの私にHTML文字列を変換するためにNSStringの

コードスニペット:適切な形式で英語テキスト方法エンコードの上

+(NSString *)getStringFromHtmlString:(NSString *)str 
{ 

    NSData *stringData = [str dataUsingEncoding:NSUTF8StringEncoding]; 
    //NSHTMLTextDocumentType 
    NSDictionary *options = @{NSDocumentTypeDocumentAttribute:NSHTMLTextDocumentType}; 

    NSAttributedString *decodedString; 
    decodedString = [[NSAttributedString alloc] initWithData:stringData 
                options:options 
              documentAttributes:NULL 
                 error:NULL]; 


    return decodedString.string; 
} 

しかし、私は符号化したい中国語テキスト。法の上使用して

ときに中国の文字列のエンコード、それは私が中国語のテキストの適切なエンコードをしたい

を返します。
enter image description here

+0

html文字列(中国語)を入力できますか。 –

+0

                 通是新型在线服务业

答えて

3

あなたはNSCharacterEncodingDocumentAttributeを追加することができます(NSUTF8StringEncoding)オプション:@

NSDictionary *options = @{NSDocumentTypeDocumentAttribute:NSHTMLTextDocumentType, NSCharacterEncodingDocumentAttribute:@(NSUTF8StringEncoding)}; 

は、それが動作します願っています。

+0

働いて..!ありがとうございました。 –

関連する問題