标记.json文件(以HTML格式)

时间:2014-12-06 17:21:30

标签: json

如何写出此.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"

    }
]}

1 个答案:

答案 0 :(得分:0)

如果你要将它放在HTML中,你可以做这样的事情。如果此json位于不同的文件中并且您正在请求它,则需要使用jquery's $.ajaxXMLHttpRequest

之类的内容

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>