Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unescape JavaScript's escape() using C#

Are the any functions in C# that handle escape/unescape like JavaScript?

I have a JSON string like this:

{"Feeds":[{"Url":"www.test.com","FeedType":"Twitter"},{"Url":"www.test2.com","FeedType":"Youtube"}]}

Which looks like this after escape()

%7B%22Feeds%22%3A%5B%7B%22Url%22%3A%22www.test.com%22%2C%22FeedType%22%3A%22Twitter%22%7D%2C%7B%22Url%22%3A%22www.test2.com%22%2C%22FeedType%22%3A%22Youtube%22%7D%5D%7D

In my C# code I would like to unescape this string so that it looks exactly the same as it did before the escape()

Is this possible?

like image 241
Martin at Mennt Avatar asked Sep 23 '10 12:09

Martin at Mennt


People also ask

What is unescape () and escape () functions?

1. The unescape() function is used to decode that string encoded by the escape() function. The escape() function in JavaScript is used for encoding a string.

What is unescape function?

The unescape function is used in JavaScript to decode a string encoded using the encode function, or to decode other types of encoded strings, such as URLs. For example, the JavaScript below will encode and then decode a string. var jif = "JavaScript is fun!"; var esc_jif = escape(jif); document.

How do you decode Unescape?

In JavaScript, to decode a string unescape() method is used. This method takes a string, which is encoded by escape() method, and decodes it. The hexadecimal characters in a string will be replaced by the actual characters they represent using unescape() method.

What is Unescape character?

The unescape() function computes a new string in which hexadecimal escape sequences are replaced with the character that it represents.


1 Answers

HttpUtility.UrlDecode should do the trick.

like image 77
Justin Niessner Avatar answered Oct 04 '22 09:10

Justin Niessner