Why I Can't Parse Json In Javascript?
JSON contains one object: results[0] = { 'MAX(id)': 1 } And this code doesn't work: var text = results[0]; var obj = JSON.parse(text); console.log(obj.MAX(id));
Solution 1:
results[0]
is already an object type
You can parse only from string to object like this:
JSON.parse('{ "MAX(id)": 1 }');
Solution 2:
Your object is already a JSON. You don't need to parse it.
To access MAX(id)
property, you can use [] notation as follows:
results[0] = { 'MAX(id)': 1 };
console.log(results[0]['MAX(id)']);
Solution 3:
Your result[0] is a real javascript object. JSON.parse transforms text into objects, so you can't parse other objects with it.
Solution 4:
var results = { 'MAX(id)': 1 };
//var text = results;//var obj = JSON.parse(text);alert(results['MAX(id)']);
Post a Comment for "Why I Can't Parse Json In Javascript?"