【发布时间】:2016-05-13 19:42:06
【问题描述】:
我有这个代码
$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 的答案,但我无法转换,因为开头的答案是,额外的字符参见示例
п»ї{"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.5 X-AspNet-版本:2.0.50727 X-Powered-By: ASP.NET 访问控制允许来源:* 访问控制允许方法:PUT、OPTIONS、POST、GET Access-Control-Allow-Headers: x-requested-with,cache-control,content-type,origin,method,SOAPAction 日期:2016 年 2 月 4 日星期四 09:08:15 GMT 连接:保持活动
由于多余的字符我无法 json_decode 字符串。可以做什么?
【问题讨论】:
-
快到 2019 年了,使用 Authorize.net API 端点时这种行为仍然存在(已针对
https://apitest.authorize.net/xml/v1/request.api进行验证)。
标签: php json authorize.net