【发布时间】:2013-08-25 23:24:54
【问题描述】:
我通过使用 jQuery 的 getjson() 方法得到了一个 Json 对象:
<script>
$(document).ready(function(){
$("button").click(function(){
$.getJSON(the_api_url, {}, function(data) {
// do something
});
});
});
});
</script>
数据是一个数组列表,格式如下:
[
{
id : "001",
name : "apple",
class : "fruit",
colour : "red"
},
{
id : "002",
name : "melon",
class : "fruit",
colour : "green"
},
{
id : "003",
name : "banana",
class : "fruit",
colour : "yellow"
}
]
我是 JavaScript 新手,不知道如何在 html 页面中解析和显示它。你们能帮我解决“//做某事”部分的代码吗?
【问题讨论】:
-
查看 api doc 进行 dom 操作 api.jquery.com/category/manipulation/dom-insertion-inside
-
看看如何使用
html()、append()等方法 -
@Arun P Johny。再见:)。我正在学习它。你能给我一个示例代码吗?
-
您的代码中有一个额外的
});
标签: javascript jquery html json