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

203
Visualizações
Javascript: Cannot get json node by name with JSON.parse()

I have an vb.net like the next:

Public Shared Function GetCountries()

    Dim lCheckOutManager As CheckOutManager = CType(HttpContext.Current.Session("CHECKOUT_MANAGER"), CheckOutManager)
    Dim dataResult = lCheckOutManager.getCountries()
    Return JsonConvert.SerializeObject(dataResult, Formatting.Indented)

End Function

Which returns a Json object to javascript like the next:

[
   {
      "ID":12,
      "NAME":"Canada",
      "INCOTERM":3
   },
   {
      "ID":60,
      "NAME":"United States",
      "INCOTERM":3
   }
]

And as I'm needing to join two json in the response and be able to access them separately, I did a little modification to my method like this:

Public Shared Function GetCountries()

    Dim lCheckOutManager As CheckOutManager = CType(HttpContext.Current.Session("CHECKOUT_MANAGER"), CheckOutManager)

    Dim dataResult = lCheckOutManager.getCountries()
    Dim strDataResult As String = "{Countries:" & JsonConvert.SerializeObject(dataResult, Formatting.Indented) & "}"

    Return JsonConvert.SerializeObject(strDataResult, Formatting.Indented)

End Function

So I can identify the first json by the node "Countries" (and then I will concatenate the second JSON), so I get a json like the next:

{
   "Countries":[
      {
         "ID":12,
         "NAME":"Canada",
         "INCOTERM":3
      },
      {
         "ID":60,
         "NAME":"United States",
         "INCOTERM":3
      }
   ]
}

But all my attempts to retrieve the "Countries" node are

being unsuccessful. Iv'e tried:

JSON.parse(results[0].d).Countries, JSON.parse(results[0].d)["Countries"], JSON.parse(results[0].d)[0], Object.keys(JSON.parse(results[0].d))[0] but none of them works, as they end in undefined or empty strings.

Any help?

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