【发布时间】:2013-01-04 16:20:57
【问题描述】:
这适用于 XML
$(document).ready(function() {
$.ajax({
type: "GET",
url: "http://api.soundcloud.com/users/123/playlists.xml?client_id=ID",
dataType: "xml",
success: parse
});
});
function parse(xml) {
$(xml).find("playlists").each(function(){
//var title = $(this).find('title').text();
$("#catTitle").append($(this).text()+ "<br />");
});
}
但是当我把它改成这个时,它就不起作用了。我在$(json).find("playlists").each(function(){ 之后放了一个 alert() 并且它永远不会被调用。有什么想法吗?
$(document).ready(function() {
$.ajax({
type: "GET",
url: "http://api.soundcloud.com/users/123/playlists.json?client_id=ID",
dataType: "json",
success: parse
});
});
function parse(json) {
$(json).find("playlists").each(function(){
//var title = $(this).find('title').text();
$("#catTitle").append($(this).text()+ "<br />");
});
}
【问题讨论】:
-
你不能用jQuery搜索
json,它是一个javascript对象或数组。像 javascript 对象或数组一样使用它。 -
是的,我有一个想法,您为什么希望它起作用?它也不是针对 XML 的,只是碰巧 XML 有足够的类似于 HTML 的结构来欺骗 JQuery
-
json 未格式化为与使用标签的 .find() 方法一起使用