如何写出此.json文件的获取数据语法?
{"Yoga":[
{
"StudioName":"Viva-Ki Yoga",
"Address":"TODAYS HOURS: 11AM - 3PM",
"Lat":"42.01560",
"Long":"-87.99354"
},
{
"StudioName":"Corepower",
"Address":"TODAYS HOURS: 11AM - 3PM",
"Lat":"39.83388",
"Long":"-75.14502"
},
{
"StudioName":"Bloom Yoga Studio",
"Address":"TODAYS HOURS: 11AM - 3PM",
"Lat":"41.955814",
"Long":"-87.693292"
}
]}
答案 0 :(得分:0)
如果你要将它放在HTML中,你可以做这样的事情。如果此json位于不同的文件中并且您正在请求它,则需要使用jquery's $.ajax或XMLHttpRequest
之类的内容
var json = document.querySelector("#myJSON").innerHTML;
try {
json = JSON.parse(json);
console.log(json);
} catch (err) {
console.log(err);
}
<script type="application/json" id="myJSON">
{
"Yoga": [
{
"StudioName": "Viva-Ki Yoga",
"Address": "TODAYS HOURS: 11AM - 3PM",
"Lat": "42.01560",
"Long": "-87.99354"
},
{
"StudioName": "Corepower",
"Address": "TODAYS HOURS: 11AM - 3PM",
"Lat": "39.83388",
"Long": "-75.14502"
},
{
"StudioName": "Bloom Yoga Studio",
"Address": "TODAYS HOURS: 11AM - 3PM",
"Lat": "41.955814",
"Long": "-87.693292"
}
]
}
</script>