使用Javascript将深度嵌套的JSON输出到HTML
因此,我可以通过进入使用Javascript将深度嵌套的JSON输出到HTML,javascript,html,json,nested,output,Javascript,Html,Json,Nested,Output,因此,我可以通过进入console.log(data.response[0].entities.url)访问所需的数据但如何将第二个实体数组输出为HTML格式。有没有一种方法可以使用for循环或其他方法分解JSON数据 $(document).ready(function () { $.getJSON('http://www.jamesam.ac/dev202/sdillon3/', function (data) { var output = '<ul data-role=
console.log(data.response[0].entities.url)访问所需的数据代码>但如何将第二个实体数组输出为HTML格式。有没有一种方法可以使用for循环或其他方法分解JSON数据
$(document).ready(function () {
$.getJSON('http://www.jamesam.ac/dev202/sdillon3/', function (data) {
var output = '<ul data-role="listview" data-filter="true">';
$.each(data.response, function (key, val) {
output += '<li>';
output += '<img src="' + val.user.profile_image_url + '" alt="' + val.text + '" />';
output += '<h3>' + val.user.name + '</h3>';
output += '<h4><i>' + val.user.screen_name + '</i></h4>';
output += '<p>' + val.text + '</p>';
output += '</li>';
}); // go through each post
output += '</ul>';
$('#feed').html(output);
console.log(data)
//console.log(data.response[0].entities.urls);//
});
$(文档).ready(函数(){
$.getJSON('http://www.jamesam.ac/dev202/sdillon3/,函数(数据){
var输出=';
$.each(data.response,函数(key,val){
输出+='- ';
输出+='';
输出+=''+val.user.name+'';
输出+=''+val.user.screen_name+'';
输出+=''+val.text+'';
输出+='
';
})//浏览每一篇文章
输出+='
';
$('#feed').html(输出);
console.log(数据)
//console.log(data.response[0].entities.url)//
});
})) 解决了
只需要写一个很好的for循环
$(document).ready(function () {
$.getJSON('http://www.jamesam.ac/dev202/sdillon3/', function (data) {
var output = '<ul data-role="listview" data-filter="true">';
$.each(data.response, function (key, val) {
output += '<li>';
output += '<img src="' + val.user.profile_image_url + '" alt="' + val.text + '" />';
output += '<h3>' + val.user.name + '</h3>';
output += '<h4><i>' + val.user.screen_name + '</i></h4>';
output += '<p>' + val.text + '</p>';
for(var i = 0; i < val.entities.urls.length; i++)
{
output+= '<a href="' + val.entities.urls[i].url +'" </a>';
}
output += '</li>';
}); // go through each post
output += '</ul>';
$('#feed').html(output);
});
$(文档).ready(函数(){
$.getJSON('http://www.jamesam.ac/dev202/sdillon3/,函数(数据){
var输出=';
$.each(data.response,函数(key,val){
输出+='- ';
输出+='';
输出+=''+val.user.name+'';
输出+=''+val.user.screen_name+'';
输出+=''+val.text+'';
对于(var i=0;i
output+='发布json以解决此问题您希望如何显示值查看url
的示例不确定我是否足够清楚,但在console.log(data.response[0].entities.url)中输出json数据时遇到问题,因为它嵌套得太深了。我如何像输出其他值一样输出它?