I have a json like this:
{"result":{"sandbox":1,"0":{"id":1106,"url":"http:\/\/www.example.com\/index1.html"},"1":{"id":9655,"url":"http:\/\/www.example.com\/index2.html"},"2":{"id":8447,"url":"http:\/\/www.example.com\/index3.html"}}}
and I’m retrieving it and then doing this:
var json = JSON.parse(data);
console.log(json.length);
but the console outputs “undefined” even if when I just log (json) it shows me the object. Why? and how can I get the length? I need it for a for loop
The json is not an array so you will not get the length.
If the json has something like [1,2,3] then it is an array
You can get the
console.log(json.result)try using the Online Parser