Reputation: 1607
I am using WebUtility.HtmlDecode
to attempt to decode a string, a portion of which is below:
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
But, WebUtility.HtmlDecode
fails to decode it, any of it. In case it matters, here is how I am generating the string:
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...
}
This is supposedly encoded JSON data, that I am reading from a POST request. How would I decode this string to regular JSON?
Edit: Lasse V. Karlsen points out that this is actually URL encoded, and that I have been barking up the wrong tree. The question still remains: how would I decode this?
Upvotes: 2
Views: 2359
Reputation: 5650
The simplest thing to do is to change HtmlDecode
to UrlDecode
.
Reason: The input string checkin=%7B%22id%22%3A...
is URL encoded, not HTML encoded.
Upvotes: 6
Reputation: 6971
HttpServerUtility.UrlDecode Method (String)
http://msdn.microsoft.com/en-us/library/6196h3wt.aspx
Upvotes: 1