小编Aen*_*ima的帖子

无法使用 UTF8 编码转换 HttpResponseMessage

我正在努力解决通常的转换问题,但不幸的是我无法找到任何适合我的具体问题的内容。

\n\n

我的应用程序正在从 php 服务器接收 System.Net.Http.HttpResponseMessage,UTF8 编码,包含一些字符,如 \\u00c3\\u00a0 (\xc3\xa0),但我无法转换它们。

\n\n
string message = await result.Content.ReadAsStringAsync();\nbyte[] messageBytes = Encoding.UTF8.GetBytes(message);\nstring newmessage = Encoding.UTF8.GetString(messageBytes, 0, messageBytes.Length);\n
Run Code Online (Sandbox Code Playgroud)\n\n

这只是我的尝试之一,但没有任何反应,生成的字符串仍然具有 \\u00c3\\u00a0 字符。

\n\n

我还阅读了一些答案,例如How to conversion a UTF-8 string into Unicode? 但这个解决方案对我不起作用。这是解决方案代码:

\n\n
public static string DecodeFromUtf8(this string utf8String)\n{\n   // copy the string as UTF-8 bytes.\n   byte[] utf8Bytes = new byte[utf8String.Length];\n   for (int i=0;i<utf8String.Length;++i) {\n      //Debug.Assert( 0 <= utf8String[i] && utf8String[i] <= 255, "the char must be in byte\'s range");\n      utf8Bytes[i] = (byte)utf8String[i];\n   }\n\n …
Run Code Online (Sandbox Code Playgroud)

c# windows utf-8 character-encoding windows-phone-8.1

3
推荐指数
1
解决办法
7975
查看次数