weixin_33688840 2017-11-10 01:27 采纳率: 0%
浏览 59

将Json导入html(表)

im trying to import a json url to html in a table. The problem is when i get the data i get 25 rows i get this on the web console: Object { data: Array[25], paging: Object } I also have the following code which is designed for only one row i guess .And i understand i have Loop over each object, appending a table row with the relevant data of each iteration. The problem is i don´t how to do it, i´m not an expert . Thank you for your help!

This is the data i get on the json url :

 {
   "data": [
      {
         "created_time": "2017-11-10T01:24:47+0000",
         "permalink_url": "https://www.facebook.com/DBZSFANSOFICIAL2/posts/1539014319521507",
         "id": "949007375188874_1539014319521507"
      },
      {
         "created_time": "2017-11-10T01:23:37+0000",
         "permalink_url": "https://www.facebook.com/DBZSFANSOFICIAL2/posts/1539013649521574",
         "id": "949007375188874_1539013649521574"
      },
      {
         "created_time": "2017-11-09T23:59:15+0000",
         "permalink_url": "https://www.facebook.com/DBZSFANSOFICIAL2/posts/1538951229527816",
         "id": "949007375188874_1538951229527816",
         "shares": {
            "count": 20
         }
      },
      {
         "created_time": "2017-11-09T23:32:30+0000",
         "permalink_url": "https://www.facebook.com/DBZSFANSOFICIAL2/posts/1538935439529395",
         "id": "949007375188874_1538935439529395"
      },

And this my code

<body>
    <input type="text" class="txtPagina">
    <button class="btnBuscar">Buscar</button>
    <table class="tabla" border='1'>
         <tr>

             <td>created time</td>
             <td>permalink url</td>
             <td>id</td>
             <td>Shares Count</td>


         </tr>
    </table>

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script>
    $(document).ready(function(){
        $('.btnBuscar').on('click', function (){
            var pagina = $('.txtPagina').val();

            //Ajax
            $.ajax({
                type: "GET",
                dataType: "json",
                url: "https://graph.facebook.com/"+pagina+"/feed?fields=created_time,permalink_url,id,shares& access_token=mytoken",
                success: function(data){
                    console.log(data);
                   $('.tabla').append("<tr><td>"+data.created_time+"</td><td>"+data.permalink_url+"</td><td>"+data.id+"</td><td>"+data.shares+"</td></tr>");
                },
                error: function (){
                    console.log("Error");
                }
            });
        });
    });
</script> 
</body>
</html>
  • 写回答

2条回答

      报告相同问题?

      相关推荐 更多相似问题

      悬赏问题

      • ¥15 房号如何排序,sql或算法
      • ¥15 macOS使用IDEA 2022.2.4打包JDK6项目报错
      • ¥20 OpenCV-Python简单轮廓寻找
      • ¥20 使用matlab进行含参数的最优化求解及数值模拟
      • ¥20 MATLAB找出一维变量中的局部极大值和局部极小值,并进行运算
      • ¥15 有Chang求三维杆单元几何非线性分析matlab代码
      • ¥50 使用unity easyar录屏功能。录屏视频整体色调很暗
      • ¥50 pyinstaller 打包问题
      • ¥15 无法使用cnssc调取网页数据
      • ¥15 Pycharm安装en_core_web_sm失败出现Could not find a version that satisfies the requirement spacy报错