2012-03-15 84 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