我正在从the服务中获取以下JSON字符串。
[{"TITLE":"asdasdasd","DESCRIPTION":"asdasd","PORTFOLIOID":1},
{"TITLE":"sss","DESCRIPTION":"sss","PORTFOLIOID":2},
{"TITLE":"sdfsdf","DESCRIPTION":"sdfsfsdf","PORTFOLIOID":3}]我可以在jquery中遍历这个数组并输出单独的键/值对吗?
发布于 2011-05-06 21:23:01
绝对一点儿没错。假设您告诉jQuery使用AJAX方法将此响应计算为JSON,您只需执行以下操作:
<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>发布于 2011-05-06 21:24:59
var a = [{"TITLE":"asdasdasd","DESCRIPTION":"asdasd","PORTFOLIOID":1}, ....]
$(a).each(function(index)
{
//this is the object in the array, index is the index of the object in the array
alert(this.TITLE + ' ' this.DESCRIPTION)
});有关更多信息,请查看jQuery文档...http://api.jquery.com/jQuery.each/
https://stackoverflow.com/questions/5912037
复制相似问题