authorize.net json 返回额外的字符 [英] authorize.net json return extra characters

查看:36
本文介绍了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, 1);
  curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
  $xmlresult = curl_exec($ch);
  $xmlError = $xmlresult;
  $json = json_decode($xmlresult, true);

我进入json但我无法转换的答案,因为一开始的答案是,额外的字符见例子

The answer I get into json but I could not convert because the in the beginning answer is, extra characters See example

п»ї{"customerPaymentProfileIdList":[],"customerShippingAddressIdList":[],"validationDirectResponseList":[],"messages":{"resultCode":"Error","message":[{"code":"E00039","text":"A duplicate record with ID 39223758 already exists."}]}}

响应头

HTTP/1.1 200 正常缓存控制:私有内容长度:232内容类型:应用程序/json;字符集=utf-8服务器:Microsoft-IIS/7.5X-AspNet 版本:2.0.50727X-Powered-By: ASP.NET访问控制允许来源:*访问控制允许方法:PUT、OPTIONS、POST、GETAccess-Control-Allow-Headers: x-requested-with,cache-control,content-type,origin,method,SOAPAction日期:2016 年 2 月 4 日星期四 09:08:15 GMT连接:保持活动

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.可以做什么?

Because of the extra characters I can not json_decode string. What can be done?

推荐答案

我在开发我的 库时遇到了同样的问题访问他们的 JSON API.在处理响应的代码中,我不得不删除删除这些字符,以便将字符串正确解码为 JSON.

I encountered the same issue when developing my library for accessing their JSON API. In the code that handles the response I had to strip those characters out in order to properly decode the string as JSON.

第 113 行:

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

这篇关于authorize.net json 返回额外的字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆