Right now I'm building an API using C#.NET, the API process the data then the result turned in json string form (not json object), but when i try to test using postman, the response body shown json data in escape string form.
My Code :
HttpResponseMessage response = new HttpResponseMessage();
NameValueCollection param;
string proc = InformationExtractor.request(Request, out param);
string json;
Process(proc, param, out json);
response = Request.CreateResponse(HttpStatusCode.OK, json);
return response;
Result :
"[{\"PK_Employee_ID\":1,\"Name\":\"test\",\"Age\":24,\"FK_Job_ID\":1,\"Created_Date\":\"2018-12-14T17:54:43.460\",\"LastUpdate_Date\":\"2018-12-14T17:54:43.460\"}]"
How to unescape the json result in response body ?
I think the problem is here :
response = Request.CreateResponse(HttpStatusCode.OK, json);
You need to specify a response format (Encoding & MediaType) before returned it.
Try changing it into this :
response.Content = new StringContent(json, Encoding.UTF8, "application/json");
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.