JSON.stringify is ignoring object properties

When an object has its own toJSON() implementation, JSON.stringify() uses the object returned from that method and stringifies that. kendo.data.Model defines it’s own toJSON() method which only returns the properties defined on the model, which is why you aren’t seeing other values (e.g. dirty, id, uid) in the string result. “If the stringify method sees … Read more

Why does JSON.stringify return empty object notation “{}” for an object that seems to have properties?

JSON.stringify includes an object’s own, enumerable properties (spec) that have values that aren’t functions or undefined (as JSON doesn’t have those), leaving out ones it inherits from its prototype, any that are defined as non-enumerable, and any whose value is a function reference or undefined. So clearly, the object you get back from getVoices()[0] has … Read more

Uncaught SyntaxError: Unexpected end of JSON input at JSON.parse ()

You are calling: JSON.parse(scatterSeries) But when you defined scatterSeries, you said: var scatterSeries = []; When you try to parse it as JSON it is converted to a string (“”), which is empty, so you reach the end of the string before having any of the possible content of a JSON text. scatterSeries is not … Read more

Convert javascript object or array to json for ajax data

I’m not entirely sure but I think you are probably surprised at how arrays are serialized in JSON. Let’s isolate the problem. Consider following code: var display = Array(); display[0] = “none”; display[1] = “block”; display[2] = “none”; console.log( JSON.stringify(display) ); This will print: [“none”,”block”,”none”] This is how JSON actually serializes array. However what you … Read more

Serialization of RegExp

If somebody would be interested, there is a nice workaround. I don’t think, that current behaviour is correct. For example, Date instance is not serialized to empty object like RegExp, though it is an object and also has no JSON representation. RegExp.prototype.toJSON = RegExp.prototype.toString; // sample var foo = { rgx: /qux$/ig, date: new Date … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)