authorize.net json返回多余的字符 [英] authorize.net json return extra characters

查看:144
本文介绍了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 内容类型:application/json;字符集= utf-8 伺服器:Microsoft-IIS/7.5 X-AspNet版本:2.0.50727 X-Powered-by:ASP.NET 访问控制允许来源:* 访问控制允许方法:PUT,OPTIONS,POST,GET Access-Control-Allow-Header:x请求,缓存控制,内容类型,来源,方法,SOAPAction 日期:2016年2月4日,星期四,格林尼治标准时间 连接:保持活动状态

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-\x1F\x80-\xFF]/', '', $responseJson);

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

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