weixin_42261843 2008-11-13 10:58
浏览 265
已采纳

jQuery遍历json数组怎么整。。

{"options":"[{\"text\":\"王家湾\",\"value\":\"9\"},{\"text\":\"李家湾\",\"valu
e\":\"10\"},{\"text\":\"邵家湾\",\"value\":\"13\"}]"}

json数组如上,在jQuery中这么遍历没效果:
$.each(data,function(i,n){
f += ''+ n.text + '';
});
不知道是哪里写错咯。。

  • 写回答

2条回答 默认 最新

  • iteye_14081 2008-11-13 11:30
    关注

    这样:

    [code="json"][
    {
    "text" : "王家湾",
    "value" : "9"
    },
    {
    "text" : "李家湾",
    "value" : "10"
    },
    {
    "text" : "邵家湾",
    "value" : "13"
    }
    ][/code]

    [code="html"]




    $(document).ready(function(){ $("#letter-e .button").click(function(){ $.getJSON("e.json",function(data){ $("#dictionary").empty(); $.each(data,function(entryIndex,entry){ var html = '<div class="entry">'; html += '<div class="text">' + entry['text'] + '</div>'; html += '<div class="value">' + entry['value'] + '</div>'; html += '</div>'; $('#dictionary').append(html); }); }); }); });


    E

    Load



    [/code]

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

报告相同问题?