Why would JSON.stringify()
return:
[]
The same happens with jQuery: $.JSON.encode()
What could cause this? I am passing in a simple array of objects, where each object has string properties. I have looped through and alerted each objects properties and all looks fine, but for some reason both the encode methods are returning []
.
It should return the value that should be added to the JSON string, as follows: If you return a Number , String , Boolean , or null , the stringified version of that value is used as the property's value. If you return a Function , Symbol , or undefined , the property is not included in the output.
The JSON array data type cannot have named keys on an array. When you pass a JavaScript array to JSON. stringify the named properties will be ignored. If you want named properties, use an Object, not an Array.
It`s ok to use it with some primitives like Numbers, Strings or Booleans. As you can see, you can just lose unsupported some data when copying your object in such a way. Moreover, JavaScript won`t even warn you about that, because calling JSON. stringify() with such data types does not throw any error.
The JSON. parse() function is used to convert a string into a JavaScript object while the JSON. stringify() function is used to convert a JavaScript object into a string.
IN your array declaration
var count_review= new Array()
instead of this use
var count_review={};
It Works!
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