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

326
Visualizações
JSON not parsing correctly using JSON.parse but $.parseJSON works

In JS I have a string variable as follows: Text JSON Data:

[{ "id" : "3", "parent" : "2", "text" : "Lack of Survey Information" },{ "id" : "4", "parent" : "3", "text" : "Lack of Surveyor Resource" },{ "id" : "5", "parent" : "3", "text" : "Land access unavailable" },{ "id" : "2", "parent" : "1", "text" : "Design Incorrect" },{ "id" : "1", "parent" : "16", "text" : "Abortive Work" },{ "id" : "6", "parent" : "1", "text" : "Wrong design info used in construction" },{ "id" : "16", "parent" : "#", "text" : "a" }]

This is output from the following code:

            console.log("Text JSON Data:"+strJSON)
        var objJSON=$.parseJSON(strJSON)
        var objJSON=JSON.parse(strJSON)

It parses using $.parseJSON but does not parse using JSON.parse (I get a bizarre "Uncaught TypeError: JSON.parse is not a function" error though it clearly is). I am using Chrome. It gets weirder, when I just use $.parseJSON successfully and then use JSON.stringify on the returned JSON object it crashes and also throws up an error.

What is weird is that I pass several other JSON strings to this function and they are parsed fine. I thought it might be something to do with the '#' symbol but it seems to parse OK in JSFiddle. I know when using VBA that sometimes an error code is triggered for a line of code when in fact the error is caused by something else. I am wondering if that is what is going on here.

What I need to understand is why this particular string is triggering the bizarre errors.

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