jQuery的,遍历JSON数组 [英] Jquery, looping over a json array

查看:185
本文介绍了jQuery的,遍历JSON数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从web服务得到以下JSON字符串。

I am getting the following JSON string from a webservice.

[{"TITLE":"asdasdasd","DESCRIPTION":"asdasd","PORTFOLIOID":1},
 {"TITLE":"sss","DESCRIPTION":"sss","PORTFOLIOID":2},
 {"TITLE":"sdfsdf","DESCRIPTION":"sdfsfsdf","PORTFOLIOID":3}]

我可以遍历该数组中jQuery和输出各键/值对?

Can i loop over this array in jquery and output the individual key/value pairs?

推荐答案

当然可以。假设你告诉jQuery来评估这个响应作为JSON的AJAX方法,你只需做到这一点:

Absolutely. Assuming you're telling jQuery to evaluate this response as JSON with the AJAX methods, you'd simply do this:

<script>
$(data).each(function(idx, obj) //this loops the array
{
    $(obj).each(function(key, value) //this loops the attributes of the object
    {
        console.log(key + ": " + value);
    }
}
</script>

这篇关于jQuery的,遍历JSON数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆