Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

260
Vistas
Why do I need to run Json.Parse twice on this List of Tuples and is that the expected behaviour?

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.

about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda