如何映射这个json ?,我已经尝试在每个json上使用多个参数,但仍然无法获得数据。
{
"data" : {
"after" : "t3_qp79c",
"before" : null,
"children" : [ {
"data" : { "url" : "http://imgur.com/c0COJ" },
"kind" : "t3"
} ],
"modhash" : ""
},
"kind" : "Listing"
}我的javascript代码
$.getJSON(reddit_api_url,function(data) {
$.each(data.children['data'], function(i, reddit) {
// Uncomment line below to show tweet data in Fire Bug console
// Very helpful to find out what is available in the tweet objects
// console.log(reddit);
// Before we continue we check that we got data
console.log(i+' : '+ reddit );
// Build the html string for the current tweet
var tweet_html = reddit.url;
// Append html string to tweet_container div
$('#tweet_container').append(tweet_html);
});
}谢谢
发布于 2012-03-11 00:47:06
返回的数据具有自己的data属性,因此您需要...
data.data.children[0]['data']...to获取最里面的数据。
如果你在迭代children,那么你应该把它传递给$.each...
$.each(data.data.children, function(i, obj) {
console.log(obj.data.url);
});https://stackoverflow.com/questions/9648205
复制相似问题