将JSON插入HTML

时间:2015-03-21 14:46:01

标签: html json

我们说我有一个类似下面的JSON文件。如何将特定值(例如0.69)插入HTML页面?

{
    "species":1,

    "animal":[
        {"day": 1,"weight": [0.69,1,2,3],"amounteaten": [22,16,15,14],"emergencies": [0,0,0,0]},
        {"day": 2,"weight": [0.5,1,3,4],"amounteaten": [22,17,15,14],"emergencies": [0,0,1,0]}

    ]
}

1 个答案:

答案 0 :(得分:4)

你在找这样的东西吗?

<div id="foo"></div>
$.getJSON('intro.json', function(obj) {
    document.getElementById("foo").textContent = obj.animal[0].weight[0];
});