Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/444.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何获取名称中有多个空格的json属性?_Javascript_Json - Fatal编程技术网

Javascript 如何获取名称中有多个空格的json属性?

Javascript 如何获取名称中有多个空格的json属性?,javascript,json,Javascript,Json,我需要得到“Größe(L x B x H)”但不能,因为它有多个空格,[“命名它”]不起作用嗨,这应该一点都不成问题,别忘了json在数组中,但我相信如果你这样做,你会没事的 "technicalData": [ { "Technologie": "Bluetooth Low Energy 4.0", "Größe (L x B x H)": "34.4 x 32.5 x 13 mm", "Gewicht": "018 kg",

我需要得到“Größe(L x B x H)”但不能,因为它有多个空格,[“命名它”]不起作用

嗨,这应该一点都不成问题,别忘了json在数组中,但我相信如果你这样做,你会没事的

"technicalData": [
      {
        "Technologie": "Bluetooth Low Energy 4.0",
        "Größe (L x B x H)": "34.4 x 32.5 x 13 mm",
        "Gewicht": "018 kg",
        "Software": "Für die Arbeit benötigt, aber nicht im Lieferumfang enthalten. Registrierung für kostenlose Software-Verwendung und Premium-Services unter: www.bosch-trackmytools.com",
        "Batterie": "CR 2032",
        "Batterie Lebensdauer": "3 J",
        "IP Schutzklasse": "IP 67",
        "Robustheit": "IK 04",
        "Befestigung": "2-Komponenten-Klebstoff oder Kabelhalter GCA 30-9 Professional"
      }
    ]

它应该返回“34.4 x 32.5 x 13mm”

首先,您必须正确定义json字典,如下所示:

technicalData[0]["Größe (L x B x H)"]
之后,您可以使用此
print()
语句获取属性。注意,感兴趣的字典位于数组中

json_dict = {"technicalData": [
      {
        "Technologie": "Bluetooth Low Energy 4.0",
        "Größe (L x B x H)": "34.4 x 32.5 x 13 mm",
        "Gewicht": "018 kg",
        "Software": "Für die Arbeit benötigt, aber nicht im Lieferumfang enthalten. Registrierung für kostenlose Software-Verwendung und Premium-Services unter: www.bosch-trackmytools.com",
        "Batterie": "CR 2032",
        "Batterie Lebensdauer": "3 J",
        "IP Schutzklasse": "IP 67",
        "Robustheit": "IK 04",
        "Befestigung": "2-Komponenten-Klebstoff oder Kabelhalter GCA 30-9 Professional"
      }
    ]
}

当你说你通过“[“命名”]”尝试时,你能告诉我们你尝试了什么吗?当我这样做时,它对我来说很好(dt.technicalData的常数d){html+=`Grö223 e(lxbxh)${d.GröeLxBxH}}}}我需要在另一个笨拙的名称上打印数据,但我做不到,也许我做错了,我很少看到json属性名带有空格,我尝试了这个${d.[GrößeLxBxH”]},但我想这是非常错误的,所以我删除了空格,并以更简单的方式完成了。完全忘记了这一点,我最终删除了所有的空格。谢谢,我需要在数组中循环,nvm,我完成了,谢谢你的时间和帮助
print(json_dict['technicalData'][0]['Größe (L x B x H)'])
# 34.4 x 32.5 x 13 mm