Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/294.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript php json_decode()无法处理编码的json字符串。解码值为空_Javascript_Php - Fatal编程技术网

Javascript php json_decode()无法处理编码的json字符串。解码值为空

Javascript php json_decode()无法处理编码的json字符串。解码值为空,javascript,php,Javascript,Php,这个JSON数据已经接受了“JSON.stringify().replace()”,然后我正在尝试在后端的php中进行JSON\u decode()。但它不起作用 节目如下: <?php $a="{\\\"data\\\":{\\\"lab\\\":[\\\"a\\\",\\\"b\\\",\\\"c\\\",\\\"4\\\",\\\"5\\\",\\\"6\\\",\\\"7\\\",\\\"8\\\",\\\"9\\\",\\\"dd\\\"],\\\"st

这个JSON数据已经接受了“JSON.stringify().replace()”,然后我正在尝试在后端的php中进行
JSON\u decode()
。但它不起作用

节目如下:

    <?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;\\\\\\\\n&lt;center&gt;&lt;img src=\\\\\\\\&quot;clouds.jpg\\\\\\\\&quot;\\/&gt;&lt;\\/center&gt;\\\\\\\\n\\\\\\\\n&lt;hr\\/&gt;\\\\\\\\n&lt;p&gt;&lt;a href=\\\\\\\\&quot;http:\\/\\/somegreatsite.com\\\\\\\\&quot;&gt;LinkName&lt;\\/a&gt;isalinktoanotherniftysite&lt;\\/p&gt;\\\\\\\\n\\\\\\\\n&lt;h1&gt;ThisisaHeader&lt;\\/h1&gt;\\\\\\\\n\\\\\\\\n&lt;h2&gt;ThisisaMediumHeader&lt;\\/h2&gt;\\\\\\\\n\\\\\\\\n&lt;p&gt;Sendmemailat&lt;a href=\\\\\\\\&quot;mailto:support@yourcompany.com\\\\\\\\&quot;&gt;support@yourcompany.com&lt;\\/a&gt;.&lt;\\/p&gt;\\\\\\\\n\\\\\\\\n&lt;p&gt;Thisisanewparagraph!&lt;\\/p&gt;\\\\\\\\n\\\\\\\\n&lt;p&gt;&lt;strong&gt;Thisisanewparagraph!&lt;\\/strong&gt;&lt;br\\/&gt;\\\\\\\\n&lt;strong&gt;&lt;em&gt;Thisisanewsentencewithoutaparagraphbreak,inbolditalics.&lt;\\/em&gt;&lt;\\/strong&gt;&lt;\\/p&gt;\\\\\\\\n\\\\\\\\n&lt;hr\\/&gt;\\\\n\\\",\\\"\\\",\\\"<p>upgraded from {{initialname}} to {{name}} on&nbsp; {{s_date}}\\\\n\\\\n<p>\\\\\\\\r\\\\\\\\n&quot;,&quot;\\\\n\\\\n<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}}\\\\n\\\\n<p>\\\\\\\\r\\\\\\\\n&quot;,&quot;\\\\n\\\\n<p>{{name}} from {{initial_name}} expires on {{expiry_date}} {{full_name}} and first {{first_name}} and last name {{last_name}}\\\\n\\\\n<p>\\\\\\\\r\\\\\\\\n\\\\n\\\\n<p>hi hello\\\\n\\\",\\\"\\\"],\\\"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\n");

        echo ($b==NULL);

        echo print_r($b,true);

?>

输出:
json解码不成功

$a不包含有效的json。这些斜杠是完全错误的,您需要转义的只是“在HTML字符串中,用'instead of'包围JSON”(因此它是$a='{…}';)。

为什么有这么多斜杠?这些都不是必需的。它不起作用,因为你有一大堆转义的“和\字符,所以它不是有效的json。实际上,它没有两组转义斜杠。为了避免json内部html中的任何语法错误,我再次对它进行编码,以确保安全解码。错误的html不应该干扰json解码,这是我的目标