简体   繁体   English

javascript JSON.parse无法从PHP解析\\ t json_encode

[英]javascript JSON.parse can't parse \t from PHP json_encode

This is my array to be encoded in PHP: 这是我要用PHP编码的数组:

array (size=1)
  0 => 
    object(stdClass)[70]
      public 'company' => string 'Mc.SUP s. r. o.' (length=15)
      public 'fullname' => string '     Jaroslav Antoň' (length=17)
      public 'id' => string '1956' (length=4)
      public 'editable' => string '1' (length=1)

The string result is: 字符串结果为:

'[{"company":"Mc.SUP s. r. o.","fullname":" \tJaroslav Anto\u0148","id":"1956","editable":"1"}]'

When trying to use Javascript JSON.parse I got this error message: SyntaxError: JSON.parse: bad control character in string literal at line 1 column 56 of the JSON data 尝试使用Javascript JSON.parse时,出现以下错误消息:SyntaxError:JSON.parse:JSON数据的第1行第56列的字符串文字中的控制字符错误

I investigated it and the problematic is \\t . 我调查了一下,有问题的是\\ t

Does somebody know the easy way how to extra escape it? 有人知道简单的方法如何额外逃脱吗? Something like options in json_encode function. 类似于json_encode函数中的选项。 Thanks in advance 提前致谢

The \\t is an escaped tab character do you really need that character for the fullname field? \\t是转义的制表符,您是否真的需要将该字符用作fullname段? You should maybe remove the tab character before doing json_encode as described here: https://stackoverflow.com/a/17176793/2030937 您可能应该按照以下说明在执行json_encode之前删除制表符: https : //stackoverflow.com/a/17176793/2030937

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM