ASP.Net Web API - JSON without accentuation %20 %C3%A7

Asked

Viewed 326 times

1

I am consuming an api but the return JSON does not come with the correct accent. in place of the mirror comes %20, for example.

in the request json I even put the encoding.UFT8.

How can I code this correctly?

private string jsonRequest = @"{'action': {'name': 'get_user_drivers','parameters': [{'driver_id': '','active_drivers': '','group_id': '','version': ''}],'session_token': '" + Helpers.TraffilogLogin.GetAuthToken() + "'}";

var content = new StringContent(jsonRequest , Encoding.UTF8, "application/json");
content.Headers.Clear();
content.Headers.Add("Content-Type", "application/x-www-form-urlencoded");

HttpClient httpClientInstance = new HttpClient();
var response = httpClientInstance.PostAsync(BaseApi.traffilogApiUrl, content).Result;

JArray groupListJson = (JArray)JObject.Parse(response.Content.ReadAsStringAsync().Result)["response"]["properties"]["data"];

1 answer

0


You can use the method HttpUtility.UrlDecode to decode your content.

string decodedUrl = HttpUtility.UrlDecode(url); //decodedUrl é o conteúdo que você precisa decodificar.

This encoding is called Percent-encoding

  • I didn’t understand. This url is the answer or the url of the same api?

  • It is the answer, the name of the method is UrlDecode Because you usually use Percent-encoding for URL, the answer you receive is fully encoded or just some attributes? for example a url field. Edit the question with the sample coded answer.

  • But in response, you would pass like this: string decodedUrl = HttpUtility.UrlDecode(RESPOSTA);

  • I edited the question with the code I’m using. Where would I use this Urldecode? They’re not all characters. So far I’ve noticed it’s space, two dots, c, ~

  • Enter the answer you receive, like the pure JSON knows?

  • Is this Httputility from System.Web? I can’t find its reference.

  • I got it. I’m using console app so it’s another name space: System.Net.Webutility.Urldecode(string)

Show 2 more comments

Browser other questions tagged

You are not signed in. Login or sign up in order to post.