【发布时间】:2018-01-05 01:24:47
【问题描述】:
我需要从 JSON 文件中获取名称,这段代码有什么问题? 我想从每个结果中获取名称值并将它们添加到正文中。
<!DOCTYPE html>
<html>
<head>
<script src="https://code.jquery.com/jquery-3.2.1.js" integrity="sha256-DZAnKJ/6XZ9si04Hgrsxu/8s717jcIzLy3oi35EouyE="crossorigin="anonymous"></script>
<script>
$.ajax({
type: "GET",
dataType: "json",
url: "https://wger.de/api/v2/exercise.json?category=8&language=2",
success: function(data){
$.each(data,function(index,object){
$("body").append("<div>"+object.name +"</div><br/>")
})
}
});
</script>
</head>
<body>
</body>
</html>
【问题讨论】:
-
如果您记录成功回调中的
data参数会是什么样子? -
显示json文件中的数据
-
@Axwell 发布 JSON 示例。您可能误读了结构。
-
@Barmar 我如何读取这个 JSON 文件的结构
-
在浏览器中打开网址。如有必要,请使用 jsonlint.com 对其进行格式化。
标签: javascript html json getjson