【问题标题】:Uncaught SyntaxError: Unexpected token i未捕获的 SyntaxError:意外的令牌 i
【发布时间】:2013-04-11 00:07:48
【问题描述】:
a = JSON.parse('["<input class="image" type="file" name="%simg_%d"/>"]');

给出上述错误。有人可以解释为什么吗? %s 是 json/javascript 中某种特殊字符串的开头吗?

【问题讨论】:

    标签: javascript json syntax-error special-characters token


    【解决方案1】:

    您不会转义引号,因此您会不断插入和退出导致无效 JSON 的字符串

    JSON.parse('["<input class=\\"image\\" type=\\"file\\" name=\\"%simg_%d\\"/>"]');
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-10-23
      • 2015-08-19
      • 2016-04-04
      • 2013-10-08
      • 2021-09-11
      • 1970-01-01
      • 2017-04-06
      相关资源
      最近更新 更多