码迷,mamicode.com
首页 > Web开发 > 详细

JSON.parse 必须用双引号包起来

时间:2018-05-05 14:48:13      阅读:257      评论:0      收藏:0      [点我收藏+]

标签:skin   tps   error   res   size   rom   expec   amp   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 必须用双引号包起来

标签:skin   tps   error   res   size   rom   expec   amp   parse   

原文地址:https://www.cnblogs.com/time-is-life/p/8994632.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!