如何获取Json对象的长度

时间:2015-04-15 07:17:22

标签: javascript json

以下是我的JSON对象

{"Decision":[{"recid":"1183","reason":"Approved as Requested","decision":"Approved","approvalamt":"","comment":""},{"recid":"662","reason":"3","decision":"Rejected","approvalamt":"","comment":""},{"recid":"752","reason":"Approved People Resources; But No Funding Approved","decision":"Approved","approvalamt":"","comment":""}]}

我如何得到这个长度。在这个例子中它应该给我3。 我的对象名称是DecisionObj,它具有上面列出的元素。

2 个答案:

答案 0 :(得分:1)



var string = '{"Decision":[{"recid":"1183","reason":"Approved as Requested","decision":"Approved","approvalamt":"","comment":""},{"recid":"662","reason":"3","decision":"Rejected","approvalamt":"","comment":""},{"recid":"752","reason":"Approved People Resources; But No Funding Approved","decision":"Approved","approvalamt":"","comment":""}]}';

var object = JSON.parse(string);

alert(object.Decision.length);




答案 1 :(得分:0)

数组具有length属性。你可以使用它。

var length =  DecisionObj.length;