c# - JSON 从 unicode 到原始格式的转换

标签 c# unicode persian

我有一个来自网络服务器的 JSON 字符串结果(波斯语)。

但是网络服务的结果是这样的:

"\u0622\u062f\u0631\u0633 \u0627\u06cc\u0645\u06cc\u0644"

而原文如下:

عملیات انجام شد

如何从unicode转换为原始格式C#

这是我的代码

HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://webserver.com/");

request.Method = "GET";
request.ContentLength = 0;
request.Credentials = CredentialCache.DefaultCredentials;
request.ContentType = "application/xml";
request.Accept = "application/xml";

using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
{
    using (Stream receiveStream = response.GetResponseStream())
    {
        using (StreamReader readStream = new StreamReader(receiveStream, Encoding.UTF8))
        {
            string strContent = readStream.ReadToEnd();

        }
    }
}

最佳答案

这看起来像 JSON。你需要 parse it .

要确认它,您可以获取输出并通过在线解码器运行它,例如 http://json.parser.online.fr/

{ "a": "\u0622\u062f\u0631\u0633 \u0627\u06cc\u0645\u06cc\u0644" }

结果是 enter image description here

所以在 C# 中解析它

string strContent = readStream.ReadToEnd(); 

dynamic stuff = JsonConvert.DeserializeObject(strContent);

您应该能够找出 Web 服务返回的结构 - 通常这是有记录的。除非您告诉人们如何使用它,否则创建 Web 服务没有多大意义。

关于c# - JSON 从 unicode 到原始格式的转换,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51173722/

相关文章:

c# - 使用 .NET Core Razor Pages 将文件下载到浏览器

c# - 如何使用MS interop excel检测c#中的合并单元格

powershell - CloudFormation 用户数据到 Base64 解码不正确

c# - 什么是可以处理代理对的 String.IndexOf(string input) 的 Unicode 安全副本?

php - POST 变量和波斯字符

java - 使用其他语言而不是英语作为java字符串(以波斯语为例)

c# - Web Api 必需参数

windows - 在 Unicode 文件上的 Mercurial 中获得可读的差异显示 (MS Windows)

android - Android 中对 TextView 的从右到左支持

c# - `X-Forwarded-For` 没有被反向代理后面的 ASP.Net Core 使用