2017-11-15 6 views
1

JSONデータをhtmlテーブルにインポートしようとしています。私はさまざまなタイプのデータを持っています。私の場合、テーブル内の "リンク"データ型を見るだけで、これはJSONデータです。 JSONをhtml(テーブル)フィルタリング結果にインポートする

{ "data": [ 
    { 
    "type": "photo", 
    "created_time": "2017-11-15T14:30:43+0000", 
    "permalink_url": "https://www.facebook.com/LaFokaES/posts/693061044378702", 
    "shares": { 
     "count": 2270 
    }, 
    "id": "104957429855736_693061044378702" 
    }, 
    { 
    "type": "link", 
    "created_time": "2017-11-15T02:34:46+0000", 
    "permalink_url": "https://www.facebook.com/LaFokaES/posts/692656794419127", 
    "shares": { 
     "count": 86 
    }, 
    "id": "104957429855736_692656794419127" 
    }, 
    { 
    "type": "photo", 
    "created_time": "2017-11-15T00:34:50+0000", 
    "permalink_url": "https://www.facebook.com/LaFokaES/posts/692493157768824", 
    "shares": { 
     "count": 1628 
    }, 
    "id": "104957429855736_692493157768824" 
    }, 
    { 
    "type": "photo", 
    "created_time": "2017-11-14T23:51:53+0000", 
    "permalink_url": "https://www.facebook.com/LaFokaES/posts/692442954440511", 
    "shares": { 
     "count": 6239 
    }, 
    "id": "104957429855736_692442954440511" 

この

は私が持っているコードです:

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

      <td>Type</td> 
      <td>created time</td> 
      <td>permalink url</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=type,created_time,permalink_url,shares&limit=25& access_token=(mytoken)", 
       success: function(data){ 


    $.each(data.data, function(i, d){ 
     var s = d.shares ? '<td>'+d.shares.count+'</td>' : ''; 
     $('.tabla').append('<tr><td>'+d.type+'</td><td>'+d.created_time+'</td><td>'+d.permalink_url+'</td>'+s+'</tr>'); 
     }); 
    }, 
        error: function(){ 
         console.log("Error"); 

そして、これは私が取得していた結果である:

enter image description here

あなたは私が写真を取得しています見ることができるようにし、リンクを見る必要があります。

答えて

関連する問題