douying7289 2013-03-20 11:48
浏览 192
已采纳

在html列表中显示json api数据

I have a json API key & I am trying to convert the json data to display in unordered list in HTML or php.

This is the API key I have : http://kippamp.uservoice.com/api/v1/forums/1/suggestions.json?client=qikbghkQYRolFTMvEXg

I am able to parse the raw json data using the below code :

<script>
$.ajax({
    type: 'GET',
    url: 'http://kippamp.uservoice.com/api/v1/forums/1/suggestions.json?client=qikbghkQYRolFTMvEXg',
    async: false,
    jsonpCallback: 'jsonCallback',
    contentType: "application/json",
    dataType: 'jsonp',
    success: function(data)
    {
        $('#jsonp-results').html(JSON.stringify(data));
        console.log(json);
    },
    error: function(e)
    {
       alert(e.message);
    }
});
</script>

but not able to parse the data to list in a formatted way.

Can someone here help me please.

Regards.

  • 写回答

2条回答 默认 最新

  • dpc46827 2013-03-20 11:57
    关注

    Just render your results in the loop. For example appending them into ul container:

    success: function (data) {
        var $ul = $('#results');
        $.each(data.suggestions, function(i, el) {
           $ul.append('<li>' + el.formatted_text + '</li>');
        });
    },
    

    http://jsfiddle.net/zvBE3/

    You just need to decide what data you need to present and what template you should use:

    var row =
        '<li>' + 
            '<h2>' + el.title + '</h2>' +
            '<div>' + el.formatted_text + '</div>'+
        '</li>';
    $ul.append(row);
    

    http://jsfiddle.net/zvBE3/3/

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 DIFY API Endpoint 问题。
  • ¥20 sub地址DHCP问题
  • ¥15 delta降尺度计算的一些细节,有偿
  • ¥15 Arduino红外遥控代码有问题
  • ¥15 数值计算离散正交多项式
  • ¥30 数值计算均差系数编程
  • ¥15 redis-full-check比较 两个集群的数据出错
  • ¥15 Matlab编程问题
  • ¥15 训练的多模态特征融合模型准确度很低怎么办
  • ¥15 kylin启动报错log4j类冲突