I am using RestSharp library to make requests to an WebApi. This is how i am doing it:
var client = new RestClient(url);
var request = new RestRequest(Method.POST);
request.AddHeader("Content-Type", "application/json");
request.AddHeader("Authorization", autentication);
RestSharp.IRestResponse response = client.Execute(request);
This works good until here. The issue that i have is that the content of the response is returning like this:
string jsonObject2 = "\"{\\\"status\\\":\\\"success\\\",\\\"entities\\\":[{\\\"bank_code\\\":2,\\\"name\\\":\\\"BANK 02\\\"},{\\\"bank_code\\\":3,\\\"name\\\":\\\"BANCK 03\\\"},{\\\"bank_code\\\":4,\\\"name\\\":\\\"BANCK 04\\\"}]}\"";
The response.content is adding 2 more \ and when i tried to deserialize and it throws an exception that it cannot convert a string to my model.
How can i resolve that the content returns in this format?
string jsonObject = "{\"status\":\"success\",\"entities\":[{\"bank_code\":2,\"name\":\"BANK 02\"},{\"bank_code\":3,\"name\":\"BANK 03\"},{\"bank_code\":4,\"name\":\"BANK 04\"}]}";
This format i can deserialize because of the correct string json format.
It works when i deserialize to string the content that returns the API and then deserialize again the string into the model type that i want.
string jsonData = JsonConvert.DeserializeObject<string>(restResponse.Content);
EntidadResponse data = JsonConvert.DeserializeObject<EntidadResponse>(jsonData);