socekt通信数据传输遇到的坑,json字符串转数组失败,坑

这两天使用php的socket网络通信,数据发送到socket服务端,传输的字节数突然变大了,经过网络传输后中间添加了一些空白字符和转义字符,那真是一顿操作猛如虎啊,我就说传输的json字 符传死都不能转换为数组,经过调试才将这个坑人的字符串转为数组

            $data=file_get_content("php://input");//满足json格式的字符串
           $start_index=strpos($data,"{");
           $data=str_replace("\\", "", $data);
            $data=str_replace(" ", "", $data);
           $data=substr($data,$start_index,strlen($data)-$start_index-1);
           $arr=json_decode($data,true);

最后问题得到解决

猜你喜欢

转载自blog.csdn.net/u014265398/article/details/89419161