我有这样的代码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,但我无法转换,因为在一开始的回答是,多余的汉字例如
п»ї{"customerPaymentProfileIdList":[],"customerShippingAddressIdList":[],"validationDirectResponseList":[],"messages":{"resultCode":"Error","message":[{"code":"E00039","text":"A duplicate record with ID 39223758 already exists."}]}}
响应头
HTTP/1.1 200 OK 缓存控制:私人 Conten t-Length:232 Content-Type:application/json;字符集= UTF-8 服务器:Microsoft-IIS/7.5 X-ASPNET-版本:2.0.50727 X供电,通过:ASP.NET 访问控制允许来源:* 访问控制 - 允许 - 方法:PUT,OPTIONS,POST,GET 日期:2016年2月4日,星期四09:08:15访问控制 - 允许 - 标题:x-requested-with,cache-control,content-type,origin,method,SOAPAction GMT 连接:保持活跃
由于额外的字符我不能json_decode字符串。可以做什么?
我看到这个表达式很多。它是否应该通过整个JSON字符串以任何顺序剥离出任意数量的这些字符?它不应该只是看前三个字符吗? '/^[\ x00- \ x1F \ x80- \ xFF] {3,3} /'' – Jason