I have encountered a bizarre case when attempting to parse some JSON data sent from a server.
The data is essentially, a set of rows of data - i.e. a list of lists, and looks something like this:
[[1,2,3],[4,5,6],[7,8,9]]
In FF (using Firebug), the received JSON data is valid, and renders correctly.
When I attempt to parse the JSON data using either of this statements, it fails:
JSON.parse()
code breaks on errorjQuery.parseJSON()
parses without complaining, yet the result of the parse is a null object
The only way I have managed to successfully parse the JSON response, is to use the dreaded eval()
statements, which is a BIG security issue.
Anyone knows what may be going on开发者_运维技巧?
I'm just starting my adventure with JavaScript and JSON, but it looks like it's not a valid JSON object. There is no key:value in this list of lists. I wold suggest changing it into list of obects containing list fields. Sth like:
[
{ list: [ 1, 2, 3 ] },
{ list: [ 1, 2, 3 ] },
{ list: [ 1, 2, 3 ] }
]
But I might be very wrong.
精彩评论