JSON.parse 必须用双引号包起来
Posted 人最大的荣耀不在于从未失败,而在于每次失败以后都能东山再起
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了JSON.parse 必须用双引号包起来相关的知识,希望对你有一定的参考价值。
Why is it that whenever I do :-
JSON.parse(‘"something"‘)
it just parses fine but when I do:-
var m = "something";
JSON.parse(m);
it gives me an error saying:-
Unexpected token s
【回答】
You‘re asking it to parse the JSON text something (not "something"). That‘s invalid JSON, strings must be in double quotes.
If you want an equivalent to your first example:
var s = ‘"something"‘;
var result = JSON.parse(s);
来自:https://stackoverflow.com/questions/18791718/json-parse-unexpected-token-s
以上是关于JSON.parse 必须用双引号包起来的主要内容,如果未能解决你的问题,请参考以下文章