如何获取JSON表的总行数?

时间:2015-02-20 09:53:28

标签: javascript html json

我只想问一下如何获取JSON表的当前总行数。我是JSON的新手所以我希望有人会回答我的问题。谢谢..

1 个答案:

答案 0 :(得分:5)

<!DOCTYPE html>
<html>
<body>

<h2>Create Object from JSON String</h2>

<p id="demo"></p>

<script>
var text = '{"employees":[' +
'{"firstName":"John","lastName":"Doe" },' +
'{"firstName":"Anna","lastName":"Smith" },' +
'{"firstName":"Peter","lastName":"Jones" }]}';

obj = JSON.parse(text);
document.getElementById("demo").innerHTML =
obj.employees[0].firstName + " " + obj.employees[0].lastName;
</script>

</body>
</html>