I'm trying to get a quick debug list of users attached to a server (.Net core 3.0). The method is as follows (I've removed anything that isn't currently being run)
public List<(string, string)> GetUsersAndCurrentRoom()
{
var result = new List<(string, string)>();
result.Add(("No users", ""));
return result;
}
The controller looks like this:
public JsonResult GetUsers()
{
var users = HubCentral.ChatHub.GetUsersAndCurrentRoom();
var str = JsonConvert.SerializeObject(users);
return Json(str);
}
The string returns as: [{"Item1":"No users","Item2":""}] when debugged.
On the JS side, I'm simply doing:
var s = JSON.parse(JSON.parse(req.responseText));
alert(req.responseText);
I'm confused why I need to run JSON.parse twice.
The result after the first one is just a string that looks like this: "[{\"Item1\":\"No users\",\"Item2\":\"\"}]". The second JSON.parse creates an object as I expect.
I'm curious why that's the case and if there's a way to avoid that, or if it is behaving as expected.