猿问

我无法从 html 中的 json 对象添加表

getJSON('http://localhost:63322/logs',

function(err, data) {

  if (err !== null) {

    alert('Something went wrong: ' + err);

  } else {


    //var myObj = JSON.parse(data);

  //  document.getElementById("demo").innerHTML = myObj.ad_soyad;



items_table = document.getElementById('items_table');

for(var ctr = 0; ctr < data.length; ctr++)

{

    items_table.innerHTML+= '<tr><td>' + data.data[ctr].uid + '</td><td>' +data.data[ctr].ad_soyad + '</td></tr>';

}


  }







      <form id="form">

    <table id='items_table' border=1>

  <tr><th colspan='2'>liste</th></tr>

  <tr><th>uid</th><th>ad_soyad</th></tr>

</table>

在这些代码中,我无法显示表格。我的 json 对象没有问题。我可以显示 json 对象,但无法在表格中显示此对象。如何解决此问题?


我的 json 对象是


{"数据":[{"uid":2,"ad_soyad":"gg"},{"uid":4,"ad_soyad":"gg"},{"uid":4,"ad_soyad":" gg"},{"uid":4,"ad_soyad":"gg"},{"uid":4,"ad_soyad":"gg"},{"uid":4,"ad_soyad":"gg" },{"uid":4,"ad_soyad":"gg"},{"uid":4,"ad_soyad":"gg"},{"uid":4,"ad_soyad":"gg"}, {"uid":4,"ad_soyad":"gg"},{"uid":4,"ad_soyad":"gg"},{"uid":4,"ad_soyad":"gg"},{" uid":4,"ad_soyad":"gg"},{"uid":4,"ad_soyad":"gg"},{"uid":4,"ad_soyad":"gg"},{"uid":4,"ad_soyad":"gg"},{"uid":6,"ad_soyad":"gg"},{"uid":6,"ad_soyad":"gg"},{" uid":10,"ad_soyad":"gg"},{"uid":16,"ad_soyad":"gg"},{"uid":190,"ad_soyad":"gg"},{"uid" :200,"ad_soyad":"gg"},{"uid":200,"ad_soyad":"gg"},{"uid":220,"ad_soyad":"gg"},{"uid":4 ,"ad_soyad":"gg"},{"uid":4,"ad_soyad":"gg"},{"uid":4,"ad_soyad":"gg"},{"uid":4," ad_soyad":"gg"},{"uid":4,"ad_soyad":"gg"},{"uid":4,"ad_soyad":"gg"},{"uid":4,"ad_soyad":"gg"}]}


谢谢你的帮助....


一只名叫tom的猫
浏览 106回答 1
1回答

汪汪一只猫

这里的问题是data父对象具有另一个data作为属性,这data实际上是这里的数组。所以,你只需要更换:for(var&nbsp;ctr&nbsp;=&nbsp;0;&nbsp;ctr&nbsp;<&nbsp;data.length;&nbsp;ctr++)有了这个:for(var&nbsp;ctr&nbsp;=&nbsp;0;&nbsp;ctr&nbsp;<&nbsp;data.data.length;&nbsp;ctr++)
随时随地看视频慕课网APP

相关分类

JavaScript
我要回答