Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

259
Visualizações
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 à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda