Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/279.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
C# WebUtility.HtmlDecode无法解码字符串_C#_Json - Fatal编程技术网

C# WebUtility.HtmlDecode无法解码字符串

C# WebUtility.HtmlDecode无法解码字符串,c#,json,C#,Json,我正在使用WebUtility.HtmlDecode尝试解码字符串,其中一部分如下: checkin=%7B%22id%22%3A%224f612730e4b071dd72e3749d%22%2C%22createdAt%22%3A1331767088%2C%22type%22%3A%22checkin%22%2C%22timeZone%22%3A%22America%5C%2FDenver%22%2C 但是,WebUtility.HtmlDecode无法对其进行任何解码。如果这很重要,以下是

我正在使用
WebUtility.HtmlDecode
尝试解码字符串,其中一部分如下:

checkin=%7B%22id%22%3A%224f612730e4b071dd72e3749d%22%2C%22createdAt%22%3A1331767088%2C%22type%22%3A%22checkin%22%2C%22timeZone%22%3A%22America%5C%2FDenver%22%2C
但是,
WebUtility.HtmlDecode
无法对其进行任何解码。如果这很重要,以下是我如何生成字符串:

public static Dictionary<String, dynamic> DeserializeRequestStream(Stream requestStream, int contentLength)
        {
            requestStream.Position = 0; //Since a custom route with post data AND an ID passed in a parameter reads this stream. Damn bugs.
            var bytes = new byte[contentLength];
            requestStream.Read(bytes, 0, contentLength);    //(int)requestStream.Length - contentLength
            var jsonResponse = System.Text.Encoding.UTF8.GetString(bytes, 0, bytes.Length);
            var decodedResponse =  WebUtility.HtmlEncode(jsonResponse);
           //...snip...
        }
publicstaticdictionary反序列化requestStream(streamrequeststream,int contentLength)
{
requestStream.Position=0;//因为带有post数据和传入参数的ID的自定义路由读取此流。该死的bug。
var bytes=新字节[contentLength];
requestStream.Read(字节,0,contentLength);//(int)requestStream.Length-contentLength
var jsonResponse=System.Text.Encoding.UTF8.GetString(bytes,0,bytes.Length);
var decodedResponse=WebUtility.HtmlEncode(jsonResponse);
//…剪断。。。
}
这应该是经过编码的JSON数据,我正在从POST请求中读取。如何将此字符串解码为常规JSON


编辑:Lasse V.Karlsen指出,这实际上是URL编码的,我一直在找错误的树。问题仍然存在:我将如何对其进行解码?

HttpServerUtility.UrlDecode方法(字符串)


最简单的方法是将
HtmlDecode
更改为
UrlDecode


原因:输入字符串
签入=%7B%22id%22%3A…
是URL编码的,而不是HTML编码的。

%7B
是URL编码的,而不是HTML编码的。HTML编码处理与符号等。谢谢!我也在谷歌上找到了这个方法。它就像一个符咒!