gpt4 book ai didi

Javascript Json 无法访问标签

转载 作者:行者123 更新时间:2023-12-03 04:13:06 25 4
gpt4 key购买 nike

我有以下 json:

{
"armament": {
"misil_aire_aire": [
{
"noms": {
"nom_rus": "R-60",
"nom_otan": "AA-8 Aphid"
},
"pes": "43.5",
"cap_explosiu": "3",
"caracteristiques_dinamiques": {
"velocitat_mach": "2.7",
"abast": "8",
"sistema_de_guia": "infraroig"
},
"pag_web": "https://en.wikipedia.org/wiki/R-60_(missile)"
},
{
"noms": {
"nom_rus": "R-27",
"nom_otan": "AA-10 Alamo"
},
"pes": "253",
"cap_explosiu": "39",
"caracteristiques_dinamiques": {
"velocitat_mach": "4.5",
"abast": "80",
"sistema_de_guia": "radar"
},
"pag_web": "https://en.wikipedia.org/wiki/R-27_(air-to-air_missile)"
},
{
"noms": {
"nom_rus": "R-73",
"nom_otan": "AA-11 Archer"
},
"pes": "105",
"cap_explosiu": "7.4",
"caracteristiques_dinamiques": {
"velocitat_mach": "2.5",
"abast": "20",
"sistema_de_guia": "infraroig"
},
"pag_web": "https://en.wikipedia.org/wiki/R-73_(missile)"
},
{
"noms": {
"nom_rus": "R-77",
"nom_otan": "AA-12 Adder"
},
"pes": "175",
"cap_explosiu": "22.5",
"caracteristiques_dinamiques": {
"velocitat_mach": "4.5",
"abast": "80",
"sistema_de_guia": "radar"
},
"pag_web": "https://en.wikipedia.org/wiki/R-77"
},
{
"noms": {
"nom_rus": "R-3",
"nom_otan": "AA-2 Atoll"
},
"pes": "90",
"cap_explosiu": "7.4",
"caracteristiques_dinamiques": {
"velocitat_mach": "2.5",
"abast": "8",
"sistema_de_guia": "infraroig"
},
"pag_web": "https://en.wikipedia.org/wiki/K-13_(missile)"
},
{
"noms": {
"nom_rus": "R-23",
"nom_otan": "AA-7 Apex"
},
"pes": "222",
"cap_explosiu": "25",
"caracteristiques_dinamiques": {
"velocitat_mach": "3",
"abast": "35",
"sistema_de_guia": "radar"
},
"pag_web": "https://en.wikipedia.org/wiki/K-13_(missile)"
}
],
"misil_aire_superficie": [
{
"noms": {
"nom_rus": "Kh-25",
"nom_otan": "AS-10 Karen"
},
"pes": "299",
"cap_explosiu": "89.6",
"caracteristiques_dinamiques": {
"velocitat_mach": "1.58",
"abast": "11",
"sistema_de_guia": "laser"
},
"pag_web": "https://en.wikipedia.org/wiki/Kh-25"
},
{
"noms": {
"nom_rus": "Kh-29",
"nom_otan": "AS-14 Kedge"
},
"pes": "660",
"cap_explosiu": "320",
"caracteristiques_dinamiques": {
"velocitat_mach": "1.23",
"abast": "10",
"sistema_de_guia": "radar"
},
"pag_web": "https://en.wikipedia.org/wiki/Kh-29"
},
{
"noms": {
"nom_rus": "Kh-31",
"nom_otan": "AS-17 Krypton"
},
"pes": "610",
"cap_explosiu": "94",
"caracteristiques_dinamiques": {
"velocitat_mach": "2.7",
"abast": "25",
"sistema_de_guia": "guia inercial"
},
"pag_web": "https://en.wikipedia.org/wiki/Kh-31"
}
]
}
}

我想放入

superficie_misils 的所有 nom_otan,我正在尝试执行以下操作:

function cargarLista(obj_Json){
avi = obj_Json.armamento.misil_aire_superficie;


for (var i = 0; i < avi.length; i++) {
misId = avi[i].noms.nom_otan;
document.getElementById("p1").innerHTML += mo + "<br>";


}
}

但是似乎不起作用,我该怎么办呢?我不确定如何到达该节点。关于如何做到这一点有什么想法吗?

最佳答案

首先,这里有一个拼写错误:

var avi = obj_Json.armamento.misil_aire_superficie;

//should be (make sure to use var so you don't populate your global scope)
var avi = obj_Json.armament.misil_aire_superficie;

其次,请确保在传递给 cargarLista() 之前或作为函数中的第一个操作时使用 JSON.parse(yourJsonStringGoesHere) 解析 JSON 对象。

var obj = JSON.parse(obj_Json);

关于Javascript Json 无法访问标签,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44247535/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com