如何打印json数据。 [英] How to print json data.
本文介绍了如何打印json数据。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个像这样的json输出数组
I have a json output array like this
{
"data": [
{
"name": "Ben Thorpe",
"id": "XXXXXXXXXXX"
},
{
"name": "Francis David",
"id": "XXXXXXXXXXX"
},
}
I想要循环遍历它并使用javascript打印出所有名称。我希望能够做到这一点。
I want to loop through it and print out the all the names using javascript. I want to be able to do this.
for(i=0;i<length;i++){
var result += response.data[i].name + ', ';
}
但是我无法使用javascript找到json对象的长度。
But I am unable to find the length of the json object using javascript.
推荐答案
response.data
是一个数组
对象,因此有一个 length
属性,可用于迭代其元素。
response.data
is an array
of objects, thus has a length
property that you can use to iterate its elements.
var result;
for(var i=0;i<response.data.length;i++)
{
result += response.data[i].name + ', ';
}
这篇关于如何打印json数据。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文