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

相关文章:

  • 2022-12-23
  • 2021-08-22
  • 2021-04-09
  • 2021-09-14
  • 2022-12-23
  • 2022-12-23
  • 2021-11-08
  • 2021-10-20
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-06-05
  • 2021-08-12
  • 2021-10-27
  • 2022-12-23
  • 2021-12-30
相关资源
相似解决方案