drvjlec1767 2017-07-14 19:36
浏览 65

php json_decode()不处理编码的JSON字符串。 解码值为NULL

This JSON data has been subjected to 'JSON.stringify().replace()' ,then i'm trying to json_decode() in php in the backend. But it wont work.

here is the program:

    <?php 
        $a="{\\\"data\\\":{\\\"lab\\\":[\\\"a\\\",\\\"b\\\",\\\"c\\\",\\\"4\\\",\\\"5\\\",\\\"6\\\",\\\"7\\\",\\\"8\\\",\\\"9\\\",\\\"dd\\\"],\\\"stats\\\":{\\\"t1\\\":{\\\"name\\\":\\\"Tier Creation\\\",\\\"t_name\\\":\\\"dd\\\",\\\"t_desc\\\":\\\"dd\\\"},\\\"t_up\\\":{\\\"d_name\\\":\\\"T Up\\\",\\\"id\\\":4,\\\"up_t\\\":\\\"Li cases\\\",\\\"up_val\\\":[\\\"1\\\",\\\"2\\\",\\\"3\\\",\\\"4\\\",\\\"5\\\",\\\"6\\\",\\\"7\\\",\\\"8\\\",9],\\\"sm_temp\\\":[\\\"\\\",\\\"\\\",\\\"\\\",\\\"\\\",\\\"\\\",\\\"\\\",\\\"\\\",\\\"\\\",\\\"\\\"],\\\"ms_end_id\\\":[\\\"\\\",\\\"\\\",\\\"\\\",\\\"\\\",\\\"\\\",\\\"\\\",\\\"\\\",\\\"\\\",\\\"\\\"],\\\"short_check\\\":[\\\"0\\\",\\\"0\\\",\\\"0\\\",\\\"0\\\",\\\"0\\\",\\\"0\\\",\\\"0\\\",\\\"0\\\",\\\"0\\\"],\\\"e_sub\\\":[\\\"\\\",\\\"\\\",\\\"\\\",\\\"\\\",\\\"\\\",\\\"test\\\",\\\"\\\",\\\"sda\\\",\\\"\\\"],\\\"e_dy\\\":[\\\"\\\",\\\"\\\",\\\"\\\",\\\"\\\",\\\"\\\",\\\"<p>&lt;title&gt;&lt;\\/title&gt;\\\\\\\
&lt;center&gt;&lt;img src=\\\\\\\\&quot;clouds.jpg\\\\\\\\&quot;\\/&gt;&lt;\\/center&gt;\\\\\\\
\\\\\\\
&lt;hr\\/&gt;\\\\\\\
&lt;p&gt;&lt;a href=\\\\\\\\&quot;http:\\/\\/somegreatsite.com\\\\\\\\&quot;&gt;LinkName&lt;\\/a&gt;isalinktoanotherniftysite&lt;\\/p&gt;\\\\\\\
\\\\\\\
&lt;h1&gt;ThisisaHeader&lt;\\/h1&gt;\\\\\\\
\\\\\\\
&lt;h2&gt;ThisisaMediumHeader&lt;\\/h2&gt;\\\\\\\
\\\\\\\
&lt;p&gt;Sendmemailat&lt;a href=\\\\\\\\&quot;mailto:support@yourcompany.com\\\\\\\\&quot;&gt;support@yourcompany.com&lt;\\/a&gt;.&lt;\\/p&gt;\\\\\\\
\\\\\\\
&lt;p&gt;Thisisanewparagraph!&lt;\\/p&gt;\\\\\\\
\\\\\\\
&lt;p&gt;&lt;strong&gt;Thisisanewparagraph!&lt;\\/strong&gt;&lt;br\\/&gt;\\\\\\\
&lt;strong&gt;&lt;em&gt;Thisisanewsentencewithoutaparagraphbreak,inbolditalics.&lt;\\/em&gt;&lt;\\/strong&gt;&lt;\\/p&gt;\\\\\\\
\\\\\\\
&lt;hr\\/&gt;\\\
\\\",\\\"\\\",\\\"<p>upgraded from {{initialname}} to {{name}} on&nbsp; {{s_date}}\\\
\\\
<p>\\\\\\\\\\\\\\
&quot;,&quot;\\\
\\\
<p style=\\\"margin-left: 40px;\\\\\\\">{{name}} reached from{{initial_name}}on expiry date {{expiry_date}} name is {{full_name}}, first&nbsp; {{first_name}} and last {{last_name}}\\\
\\\
<p>\\\\\\\\\\\\\\
&quot;,&quot;\\\
\\\
<p>{{name}} from {{initial_name}} expires on {{expiry_date}} {{full_name}} and first {{first_name}} and last name {{last_name}}\\\
\\\
<p>\\\\\\\\\\\\\\
\\\
\\\
<p>hi hello\\\
\\\",\\\"\\\"],\\\"t_id\\\":[\\\"\\\",\\\"\\\",\\\"\\\",\\\"\\\",\\\"\\\",\\\"\\\",\\\"\\\",\\\"\\\",\\\"\\\"],\\\"acc_id\\\":[\\\"\\\",\\\"\\\",\\\"\\\",\\\"\\\",\\\"\\\",\\\"\\\",\\\"\\\",\\\"\\\",\\\"\\\"]},\\\"aton\\\":{\\\"dime\\\":\\\"Po lcon\\\",\\\"grp\\\":{\\\"PRO\\\":{\\\"name\\\":\\\"PRO\\\",\\\"id\\\":2,\\\"a_type\\\":\\\"In terms of gg\\\",\\\"all\\\":[\\\"10.0\\\",\\\"20.0\\\",\\\"20.0\\\",\\\"100\\\",\\\"100\\\",\\\"100\\\",\\\"110\\\",\\\"100\\\",\\\"100\\\",100]},\\\"DEFAULT\\\":{\\\"name\\\":\\\"DEFAULT_ALL\\\",\\\"id\\\":3,\\\"al_type\\\":\\\"rated - In terms of gg\\\",\\\"alloc_val\\\":[\\\"100\\\",\\\"100\\\",\\\"100\\\",\\\"100\\\",\\\"100\\\",\\\"100\\\",\\\"120\\\",\\\"100\\\",\\\"100\\\",100]}}},\\\"finalize\\\":{\\\"lay_nam\\\":\\\"Fin\\\"}},\\\"curr_sym\\\":\\\"\\\"},\\\"ash_age\\\":\\\"\\\",\\\"log\\\":[]}";




        $b = array();
        $b=json_decode($a,"\0") or die("json decode unsuccessful
");

        echo ($b==NULL);

        echo print_r($b,true);

?>

output: json decode unsuccessful

  • 写回答

1条回答 默认 最新

  • douwen9345 2017-07-14 19:55
    关注

    $a doesn't contain valid JSON. Those slashes are completely wrong, all you need to escape are the " inside the HTML strings and surround the JSON with ' instead of " (so it's $a = '{.....}'; ).

    评论

报告相同问题?

悬赏问题

  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器