I am planning to do a JSON Response from an ASP.NET Core Controller but it is not as simple as I thought.
A simple string like {"ConfigValue":"192.168.1.125:1880"}
should be serialized to a JsonObject and this object shall be part of the JSON Response.
But what the return Json(str) response is something like
{\u0022ConfigValue\u0022:\u0022192.168.1.125:1880\u0022}
I have no clue how to get rid of \u0022
public class commonController : Microsoft.AspNetCore.Mvc.Controller
{
private IConfiguration config;
public commonController(IConfiguration configuration)
{
config = configuration;
}
// GET
[Route("getConfigEntry/{key?}")]
public JsonResult getConfigEntry(string? key)
{
Dictionary<string, string> dict = new Dictionary<string, string>
{
{"ConfigValue", "192.168.1.125:1880"}
};
str = JsonConvert.SerializeObject(dict,Formatting.None); //from debugger variable viewer {"ConfigValue":"192.168.1.125:1880"}
return Json(str); // "{\u0022ConfigValue\u0022:\u0022192.168.1.125:1880\u0022}"
}
}