Decode string encoded by javascript in C #

0

Hello, this is the following .. In the site I am building, I record an information in the database, this information is a json, to be able to send this data to the database, I code them by javascript like this: p>

encodeURI(dados);

After that I send it via jquery and save it to the database ..

using System;
using System.Net;

...
Conecto ao banco de dados, pego a informação do jeito que está la em um string, e peço pra mostrar numa show box
MessageBox.Show(WebUtility.HtmlDecode(pedidos));

But it is not decoding, the result is still coming back just as it is in the database, all encoded as if it were a URI

%5B%0A%09%7B%0A%09%09%22id%22%3A%221%22%2C%0A%09%09%22produto%22%3A%22VENEZA%22%2C%0A%09%09%22preco%22%3A%2242.00%22%2C%0A%09%09%22quantidade%22%3A1%0A%09%7D%0A%5D
    
asked by anonymous 15.05.2018 / 21:47

1 answer

3

Try to use HttpUtility.UrlDecode of library System.Web

String teste = "%5B%0A%09%7B%0A%09%09%22id%22%3A%221%22%2C%0A%09%09%22produto%22%3A%22VENEZA%22%2C%0A%09%09%22preco%22%3A%2242.00%22%2C%0A%09%09%22quantidade%22%3A1%0A%09%7D%0A%5D";

Console.WriteLine(HttpUtility.UrlDecode(teste));

Return:

[
    {
        "id":"1",
        "produto":"VENEZA",
        "preco":"42.00",
        "quantidade":1
    }
]

Recommended reading: What's the difference between : UrlEncode, EscapeUriString and EscapeDataString

    
15.05.2018 / 21:57