Ajax 有效的JSON提要|空白页
这是我的jsonp提要:(JSONLint有效) 以下是我的getJSON脚本:Ajax 有效的JSON提要|空白页,ajax,json,jsonp,getjson,Ajax,Json,Jsonp,Getjson,这是我的jsonp提要:(JSONLint有效) 以下是我的getJSON脚本: <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <script src="http://code.jquery.com/jquery-latest.js"></script> <script> $(document).ready(function () { $.getJSON
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<script src="http://code.jquery.com/jquery-latest.js"></script>
<script>
$(document).ready(function () {
$.getJSON("http://www.letheatredelorient.fr/saison/data.jsonp?callback=", function (data) {
$.each(data.Items, function (i, node) {
var title = node.titre;
$("#myTitle").html(title);
});
});
});
</script>
</head>
<body>
<div id="myTitle"></div>
</body>
</html>
$(文档).ready(函数(){
$.getJSON(“http://www.letheatredelorient.fr/saison/data.jsonp?callback=,函数(数据){
$.each(数据项、函数(i、节点){
var title=node.titre;
$(“#myTitle”).html(标题);
});
});
});
这真的很简单。但是,它得到了提要,但没有解析它。有什么想法吗?试试这个:
var title = node.node.titre;
在您的代码中,节点是Item对象,节点在其中,这是否更清楚
$.getJSON("http://www.letheatredelorient.fr/saison/data.jsonp?callback=", function (data) {
$.each(data.Items, function (i, item) {
//For each item in Items
var title = item.node.titre;
$("#myTitle").html(title);
});
});
这是您的json,我添加了注释,您正在遍历包含节点的项目:
{
"Items": [
-item{
"node": {
"titre": "La Faculté",
"image": "http://www.letheatredelorient.fr/sites/default/files/imagecache/130/saison/spectacles/faculte/photos/faculte-web2calainfonteray.jpg"
}
},
-item{
"node": {
"titre": "Nouveau Roman",
"image": "http://www.letheatredelorient.fr/sites/default/files/imagecache/130/saison/spectacles/nouveau-roman/photos/1210-nouveauroman-04cjeanlouisfernandez.jpg"
}
}
]
}
是的,谢谢!这是可行的,但我试着去理解,为什么会有第二层的“节点”。因为你不是在节点之间循环,你是在它们的容器对象之间循环——我现在要修改上面我理解的内容。非常感谢您抽出时间。