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

89
Vistas
Parece que no puedo hacer referencia a los datos en un archivo JSON complejo, probablemente solo mi sintaxis

Soy un novato así que por favor perdóname. Tengo el siguiente archivo JSON:

 `{ "Series": {"Next": [ { "Name": "Cheese", "Price" : 2.50, "Location": "Refrigerated foods"}, { "Name": "Crisps", "Price" : 3, "Location": "the Snack isle"}, { "Name": "Pizza", "Price" : 4, "Location": "Refrigerated foods"}, { "Name": "Chocolate", "Price" : 1.50, "Location": "the Snack isle"}, { "Name": "Self-raising flour", "Price" : 1.50, "Location": "Home baking"}, { "Name": "Ground almonds", "Price" : 3, "Location": "Home baking"} ]}`

Estoy tratando de hacer referencia al nombre, la ubicación y el precio, pero ahora funciona. Aquí está el código JavaScript que estoy usando:

 .then(function(json) { for(var i = 0; i < json.Next.length; i++) { var listItem = document.createElement('li_prod'); listItem.innerHTML = '<strong_prod>' + json.Next[i].Name + '</strong_prod>'; listItem.innerHTML +=' can be found in ' + json.Next[i].Location + '.'; listItem.innerHTML +=' Cost: <strong_prod>£' + json.Next[i].Price + '</strong_prod>'; myList.appendChild(listItem); }

ese código no está recogiendo el nombre, la ubicación o el precio. ¿Cómo puedo referenciar los datos? Algo así como json.Series.Next[i].Name?

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

con la estructura de su objeto es más json.Series.Next en lugar de json.Next

 var json = { "Series": { "Next": [{ "Name": "Cheese", "Price": 2.50, "Location": "Refrigerated foods" }, { "Name": "Crisps", "Price": 3, "Location": "the Snack isle" }, { "Name": "Pizza", "Price": 4, "Location": "Refrigerated foods" }, { "Name": "Chocolate", "Price": 1.50, "Location": "the Snack isle" }, { "Name": "Self-raising flour", "Price": 1.50, "Location": "Home baking" }, { "Name": "Ground almonds", "Price": 3, "Location": "Home baking" } ] } } var myList = document.getElementById('my-list'); for (var i = 0; i < json.Series.Next.length; i++) { var listItem = document.createElement('li_prod'); listItem.innerHTML = '<strong_prod>' + json.Series.Next[i].Name + '</strong_prod>'; listItem.innerHTML += ' can be found in ' + json.Series.Next[i].Location + '.'; listItem.innerHTML += ' Cost: <strong_prod>£' + json.Series.Next[i].Price + '</strong_prod>'; myList.appendChild(listItem); }
 <div id="my-list"> </div>

about 4 years ago · Juan Pablo Isaza Denunciar
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