我收到错误:注意(8):unserialize()[function.unserialize]:当我尝试在页面中显示JSON编码数组时,错误偏移0为743字节。
我在foreach循环中迭代所有用户以获取用户详细信息作为数组格式。数组格式如下所示:
$userDetails =
Array
(
[id] => 12121212
[enc_userid] => QWQWQWQWdssd
[img_path] => http://192.168.1.XX/pjt/images/getuserphoto/SDSDSDSDSD/1/big/
[msg_icon] => http://192.168.1.XX/pjt/img/sd/4a-icons/msg.png
[rdd_icon] => http://192.168.1.XX/pjt/img/sd/4a-icons/invite.png
[profile_path] => http://192.168.1.XX/pjt/user/sd/HJHJHJH
[name] => XXX XXXXXXXXX
[type] => IND
[photo] => XXXXX.jpg
[designation] => XXXX XXXXXXXXXXXXXXXXX
[company] => XXXXXXXXXXXXXX Pvt Ltd
[insid] =>
[status] => 1
[city] => XDXX, XXX,XXX
[xxxx_id] => XXXX
)
然后这个数组被序列化并显示如下:
echo serialize($userDetails);
foreach循环如下所示:
$ui_array = array();
foreach ($search_data as $key => $val) {
$ui_array[] = unserialize($this->function_to_fetch_user_details($user_id));
}
echo json_encode($ui_array);exit;
但是我在JSON数组的开头会得到一个假的,如:
[false,{"id":"11168","enc_userid":"dsdsdsd","img_path":"http:\/\/192.168.1.dd\/sdsdsd\/images\/getuserphoto\/sdsdsd\/1\/big\/","msg_icon":"http:\/\/192.168.1.sd\/sdsd\/img\/sdheme\/icons\/msg.png" ...................
带有错误的注意事项(8):unserialize()[function.unserialize]:偏移0处的错误为743字节。
我不明白为什么这个错误现在正在发生,因为它以前工作得很好。 任何帮助都会非常有帮助,谢谢!
答案 0 :(得分:0)
您获得错误的可能原因可能与您收到错误的原因相同:
我们调试:
将您的代码修改为:
$ui_array = array();
foreach ($search_data as $key => $val) {
serializedData = $this->function_to_fetch_user_details($user_id);
$array = unserialize(serializedData);
if($array == false) {
die("error Found with : " . serializedData;
}
$ui_array[] = unserialize($this->function_to_fetch_user_details($user_id));
}
echo json_encode($ui_array);exit;