【发布时间】:2016-07-13 22:20:24
【问题描述】:
我是 javascript 新手,我想计算这个 json 字符串的值:
{
"files": [
{
"name": "doc1.pdf",
"title": "networking",
"path": "mfpreader.comze.com\/files\/doc1.pdf"
},
{
"name": "doc2.pdf",
"title": "Armoogum",
"path": "mfpreader.comze.com\/files\/doc2.pdf"
}
]
}
json 保存在 res.responseJSON.data 中。
这是我尝试过的代码:
$("#demo").html(JSON.stringify(res.responseJSON.data));
var jsonObject = JSON.parse(res.responseJSON.data);
var propertyNames = Object.keys(jsonObject);
alert("There are "+propertyNames.length+" properties in the object");
get 的值为 1。它应该是 2,因为我们有 2 个文档。
请给我一些。谢谢
【问题讨论】:
-
propertyNames.name.length- 计算name字段而不是files字段 -
从文件中获取数组,然后检查数组的长度
标签: javascript json