2012-03-15 83 views
2

我使用WebUtility.HtmlDecode去试图解码一个字符串,其中一部分是低于:WebUtility.HtmlDecode无法解码的String

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... 
     } 

推测这是编码的JSON数据,那我从POST请求阅读。我将如何将此字符串解码为常规JSON?

编辑: Lasse V. Karlsen指出,这实际上是URL编码,而且我一直在吠叫错误的树。问题依然存在:我将如何解码?

+3

'%7B'为* URL *编码,而非* HTML *编码。 HTML编码处理和符号等。 – 2012-03-15 00:58:12

回答

6

做最简单的事情就是改变HtmlDecodeUrlDecode

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

+0

谢谢!我也在Google上找到了这种方法。它像一个魅力! – 2012-03-15 02:06:08