简体   繁体   中英

jQuery.ParseJSON returns a string

I'm getting a string which represents a JSON Object (it's a valid JSON string according to JSONLint).

When I call :

console.log(JSON.parse(datasource_graphe_un));

It returns a string, confirmed by :

console.log(typeof jQuery.parseJSON(datasource_graphe_un));

returning string.

Here's an example of the string I try to parse :

[ {"id":195197,"val":9800,"date":"2009/05/11","ax":1242023901,"number":8,"valval":9200} , ... ]

Why can't I parse it ? And why jQuery.parseJSON returns a string ?

Thank's

是的,可能是两次编码(例如你使用JSON.stringify()然后使用encodeURIcomponent())。

Using Chrome's Console, this line works fine for me. You may have to iterate through your array if you are trying to parse several results being stored in the variable datasource_graphe_un.

  var k = $.parseJSON('{"id":195197,"val":9800,"date":"2009/05/11","ax":1242023901,"number":8,"valval":9200}');

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM