将json打破为chunks对象的错误,因为它不明白

时间:2016-03-31 17:38:54

标签: json

当我尝试从url加载json数据并转换为html表时。有一个位置列,它提供错误对象对象,不反映纬度和经度。我需要做的就是打破它并使用strin concat display lati和longi。

   <script>
    $.ajax({
      url: "https://abcdefghijk.com ",
      //force to handle it as text
      dataType: "text",
      success: function(data) {

      //data downloaded so we call parseJSON function 
      //and pass downloaded data
      var json = $.parseJSON(data);
      //now json variable contains data in json format
      //let's display a few items

      // we'll put all our html in here for now
      var html = '';
      for (var i=0;i<json.length;++i)
      {
      // if on first loop, create the col headers  style="position: fixed; min-width: 100px; width:100%;"
      if(i===0)
      {
            html += '<thead><tr>';
            $.each(json[i], function(key, value){
            html += '<th style="font-size:15px; text-align: center;                 background-color: #6F5091;">'+key+'</th>' ;
            });
            //html += '</thead></tr>';
        }

      // loop through all the json objects and for every key add a column with the value
            html += '<tr>';
            $.each(json[i], function(key, value)
            {
               if(key=='location')
               {
               var resultJSON = value;
                html += '<td>'+resultJSON+'</td>' ;
                var data = JSON.parse(resultJSON);
                for (var key in data)
                {
                //console.log(key + ' : ' + data[key]);
                //   alert(key + ' --> ' + data[key]);
                //}
                }
                else
                {
                   html += '<td>'+value+'</td>' ;
                }
            });
        html += '</tr>';
        }
        // push all the html in one go to the page
        $('#results').append(html);
      }
    });
   </script>    

0 个答案:

没有答案