繁体   English   中英

发布json_encode数据时,请求的JSON解析失败,我该如何删除“ \\”

[英]Requested JSON parse failed while post json_encode data , how can I revmoe “\”

$valueArr=htmlspecialchars(json_encode($event), ENT_QUOTES, 'UTF-8');

我正在从发送json_encode($valueArr)

<a href="javascript:void(0)"  id="event_<?=$event->event_id?>"  onclick='getDetailsEvent(<?php echo $valueArr;?>)' >

到这个功能

 <script>
    function getDetailsEvent(eObj){
        var edStr=JSON.stringify(eObj);
        m.ajax({
            type: "POST",
            url: "<?php echo SITEPATH;?>/socialuser/event_calender/gethtml.php",
            data: "ed="+edStr+"&t=<?=time()?>",
            contentType: 'application/json; charset=utf-8',
            dataType: "json",
            error: function(jqXHR, exception){
                if (jqXHR.status === 0){
                    alert('Not connect.\n Verify Network.');
                }else if (jqXHR.status == 404){
                    alert('Requested page not found. [404]');
                }else if (jqXHR.status == 500){
                    alert('Internal Server Error [500].');
                }else if (exception === 'parsererror'){
                    alert('Requested JSON parse failed.');
                }else if (exception === 'timeout'){
                    alert('Time out error.');
                }else if (exception === 'abort'){
                    alert('Ajax request aborted.');
                }else{
                    alert('Uncaught Error.\n' + jqXHR.responseText);
                }
            },
            beforeSend:function(){
                var bSend = 'l o a d i n g . . . ';
                m('#load').show();
                m('#load').html(bSend);
            },
            success: function(response){
                m('#evenDetails').html(response);
            }
        });
    }
</script>

现在,在此功能上,如果我不在本地服务器上使用“ datatype:” json“”,那么一切都会正常工作,但是在服务器上却无法正常工作。

它会给与错误

else if (exception === 'parsererror'){
                        alert('Requested JSON parse failed.');

在ajax电话上..

在帖子页面上打印帖子数据时,数据像这样

{\"first_name\":\"Pradeep\",\"last_name\":\"Kumar\",\"profile_image\":\"thumbnail_10000022_1359466283.jpg\",\"category\":\"Restaurant\",\"category_image\":\"icon_restaurants.png\",\"category_icons\":\"restaurants_icon.png\",\"event_id\":\"17\",\"social_users_id\":\"10000022\",\"location\":\"new, Thandla, Madhya Pradesh 457777, India\",\"lat\":\"23.0048561\",\"lng\":\"74.57584440000005\",\"title\":\"dasdasd\",\"event\":\"Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry\'s standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop p\",\"pic_event\":\"517a1d4a38d411366957386.jpg\",\"event_type\":\"1\",\"day\":\"15\",\"month\":\"5\",\"year\":\"2013\",\"date\":\"1368556200\",\"time\":\"0\"}

我的问题是,如果我得到了这种类型的数据,我怎么能json_decode,因为它包含不会解析服务器上数据的“ \\”。

htmlspecialchars函数添加了特殊字符以避免安全漏洞,其中一个字符是'/'char。 我建议只使用json_encode($event)

暂无
暂无

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

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