我有这个代码
$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
内容类型:application/json;字符集=utf-8
服务器:微软-IIS/7.5
X-AspNet-版本:2.0.50727
X-Powered-By: ASP.NET
访问控制允许来源:*
访问控制允许方法:PUT、OPTIONS、POST、GET
访问控制允许标头:x-requested-with、缓存控制、内容类型、来源、方法、SOAPAction
日期:2016 年 2 月 4 日星期四 09:08:15 GMT
连接:保持活动状态
由于额外的字符,我无法 json_decode 字符串。可以做什么?