2

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));
1
  • 2
    Your results[0] is already an object, not a JSON string, so no need to parse it. Then you should use obj['Max(id)'] because it's a string, not a method. Commented Jul 3, 2015 at 9:18

4 Answers 4

1

results[0] is already an object type

You can parse only from string to object like this:

JSON.parse('{ "MAX(id)": 1 }');
Sign up to request clarification or add additional context in comments.

Comments

1

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)']);

Comments

1

Your result[0] is a real javascript object. JSON.parse transforms text into objects, so you can't parse other objects with it.

Comments

1

    var results = { 'MAX(id)': 1 };
    //var text = results;
    //var obj = JSON.parse(text);
    alert(results['MAX(id)']);

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.