开发者

Parsing JSON data in javascript

开发者 https://www.devze.com 2023-02-09 18:07 出处:网络
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:

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:

  1. JSON.parse() code breaks on error

  2. jQuery.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.

0

精彩评论

暂无评论...
验证码 换一张
取 消