php – authorize.net json返回额外的字符
我有这个代码
$ch = curl_init(); curl_setopt($ch,CURLOPT_URL,$url); curl_setopt($ch,CURLOPT_RETURNTRANSFER,1); curl_setopt($ch,CURLOPT_HTTPHEADER,Array("'Content-Type: application/json; charset=utf-8'")); curl_setopt($ch,CURLOPT_HEADER,0); curl_setopt($ch,CURLOPT_POSTFIELDS,json_encode($data_str)); curl_setopt($ch,CURLOPT_POST,CURLOPT_SSL_VERIFYPEER,0); $xmlresult = curl_exec($ch); $xmlError = $xmlresult; $json = json_decode($xmlresult,true); 我进入json的答案,但我无法转换,因为在开头答案是,额外的字符见例子 п??{"customerPaymentProfileIdList":[],"customerShippingAddressIdList":[],"validationDirectResponseList":[],"messages":{"resultCode":"Error","message":[{"code":"E00039","text":"A duplicate record with ID 39223758 already exists."}]}} 响应标题
因为额外的字符我不能json_decode字符串.可以做些什么? 解决方法
我在开发
library for accessing their JSON API时遇到了同样的问题.在
the code that handles the response中,我不得不将这些字符去掉,以便将字符串正确解码为JSON.
第113行: $this->responseJson = preg_replace('/[x00-x1Fx80-xFF]/','',$responseJson); (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |