加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > PHP教程 > 正文

php – authorize.net json返回额外的字符

发布时间:2020-12-13 16:59:24 所属栏目:PHP教程 来源:网络整理
导读:我有这个代码 $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);
我有这个代码

$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."}]}}

响应标题

HTTP/1.1 200 OK
Cache-Control: private
Content-Length: 232
Content-Type: application/json; charset=utf-8
Server: Microsoft-IIS/7.5
X-AspNet-Version: 2.0.50727
X-Powered-By: ASP.NET
Access-Control-Allow-Origin: *
Access-Control-Allow-Methods: PUT,OPTIONS,POST,GET
Access-Control-Allow-Headers: x-requested-with,cache-control,content-type,origin,method,SOAPAction
Date: Thu,04 Feb 2016 09:08:15 GMT
Connection: keep-alive

因为额外的字符我不能json_decode字符串.可以做些什么?

解决方法

我在开发 library for accessing their JSON API时遇到了同样的问题.在 the code that handles the response中,我不得不将这些字符去掉,以便将字符串正确解码为JSON.

第113行:

$this->responseJson = preg_replace('/[x00-x1Fx80-xFF]/','',$responseJson);

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读