我有這樣的代碼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