I'm new to javascript and i want to count the values of this json string:
{
"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"
}
]
}
the json is saved in the res.responseJSON.data.
here is the code i tried:
$("#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");
The value is get is 1. It should be 2 since we have 2 documents.
can i have some please. Thanks
For the required output what you want you have to do like below
var v={"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"}]};
console.log(v.files.length)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With