Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

258
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!