JSON解析中的错误控制字符错误 [英] bad control character error in json parse

查看:199
本文介绍了JSON解析中的错误控制字符错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

解析JSON对象时,我在Firebug控制台中收到错误的控制字符"错误.这个站点上有很多问题和解决方案.但我无法解决这个问题.我相信我在做些愚蠢的事情.请指出我的错误.

When parsing a JSON object I am getting "bad control character" error in the Firebug console. There are lot of questions and solutions in this site; but I am unable to crack this issue. I believe I am doing something silly. Please point me to my mistake.

JS Fiddle: http://jsfiddle.net/Purus/Eqz2r/

JS Fiddle: http://jsfiddle.net/Purus/Eqz2r/

如果我们将json数据更改为纯文本而不是html标签,那么它将起作用.

If we change the json data to a plain text instead of html tags, it works.

错误:

SyntaxError: JSON.parse: bad control character in string literal
someVal = JSON.parse(sign);

注意:

  • 使用json_encode从PHP函数获取JSON数据 功能.
  • json输出在jsonlint中看起来有效
  • The JSON data is obtained from a PHP function using json_encode function.
  • The json output looks valid in jsonlint

下面是我使用的代码.

$(document).ready(function () {
   var sign = '{"data":"<br\/><br\/>----------<br \/>\r\nFrom Yahoo Team<br \/>\r\n<a href=\"http:\/\/localhost\/base\/1-yahoo-logo.jpg\" target=\"_blank\"><img style=\"padding: 5px;\" src=\"http:\/\/localhost\/plugins\/1-yahoo-logo.jpg\" height=\"120\" width=\"196\" \/><\/a>"}';

   someVal = JSON.parse(sign);
   $(".demo").append(someVal.data);
});

推荐答案

您需要逃脱转义:)

使用双精度\\代替\

http://jsfiddle.net/Eqz2r/2/

这篇关于JSON解析中的错误控制字符错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆