0

I could use some help with the syntax when using jquery to parse this json data coming back from the server. I have tried several examples from stackoverflow and other sites and for some reason I keep getting undefined as the out put instead of the id numbers. Each one should be its own line.

{
  "ROWCOUNT":7,
  "COLUMNS":["ID"],
  "DATA":{"id":"211","212","213","221","222","223","232"]}
}
4
  • 4
    please add the code you have tried to use! Commented Jan 12, 2012 at 18:31
  • 1
    can you show us what you have tried please Commented Jan 12, 2012 at 18:32
  • 1
    Your json is not valid, look at the "DATA": part Commented Jan 12, 2012 at 18:35
  • Okay I am using coldfusion to create the json using SerializeJSON(query,true) If I remove the true I get {"COLUMNS":["ID"],"DATA":[["211"],["212"],["213"],["221"],["222"],["223"],["231"]‌​,["232"],["233"],["241"]]} I am currently using $.each(data, function(i,item) {output i} the i comes out now as 0 through 6 not the data. Commented Jan 12, 2012 at 18:46

4 Answers 4

4

If you pass your JSON through a validator such as JSONLint you'll see that the JSON is not correct, which can be the reason for the errror.

This is what JSONLint shows:

Parse error on line 8:
..."211",        "212",        "213",   
----------------------^
Expecting ':

Which is easy to spot when you add some whitespace:

{
    "ROWCOUNT": 7,
    "COLUMNS": [
        "ID"
    ],
    "DATA": {
        "id": "211",
        "212",
        "213",
        "221",
        "222",
        "223",
        "232"
    ]
}
}
Sign up to request clarification or add additional context in comments.

1 Comment

Okay I am using coldfusion to create the json using SerializeJSON(query,true) If I remove the true I get {"COLUMNS":["ID"],"DATA":[["211"],["212"],["213"],["221"],["222"],["223"],["231"],["232"],["233"],["241"]]}
0

You have wrong syntax with square brackets:

  "DATA":{"id":"211","212","213","221","222","223","232"]}

should be:

  "DATA":{"id":["211","212","213","221","222","223","232"]}

Comments

0

I don't know about what code you have so far used to to try to parse it, but I can tell you that the JSON code above is syntactically wrong. Use this instead:

{
  "ROWCOUNT":7,
  "COLUMNS":["ID"],
  "DATA":{"id":"211","212","213","221","222","223","232"}
}

You had an extra square brace.

Comments

0

The problem appears to be that you are missing an open [ after the id declaration. It should look like the following

{"ROWCOUNT":7, "COLUMNS":["ID"], "DATA":{"id":["211","212","213","221","222","223","232"]}}

Example usage

var json = '{"ROWCOUNT":7, "COLUMNS":["ID"], "DATA":{"id":["211","212","213","221","222","223","232"]}}';
var obj = $.parseJSON(json);
console.log(obj);

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.