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