我連接到通過電子商務應用程序的命令行中執行以下操作:檢索捲曲信息json_decode
curl -u xxxxxx: https://xxxx/xxx
它返回是這樣的:
{ "charge_enabled": true,
"details_submitted": true,
"email": "[email protected]",
"id": "xxxx",
"statement_descriptor": "xxxx",
"xxxx": [ "USD" ]
}
當我改變這PHP來在腳本中運行此操作,我也可以通過以下方法檢索相同的信息:
$ch = curl_init('https://xxxx/xxxx');
$options = array(
CURLOPT_USERPWD=> $xxxxxx
);
curl_setopt_array($ch, $options);
$result2= curl_exec($ch);
但是,當我嘗試檢索電子郵件等個人信息,我無法這樣做。我試着通過json_decode
這樣做如下:
$parsedresult = json_decode($result2,true);
$emailretrieve = $parsedresult["email"];
此只返回一個數字1
,而不是電子郵件地址。
任何人都可以幫助並告訴我什麼是錯的嗎?我嘗試了很多已經發布在StackOverflow上的東西,但沒有一個能夠工作。
你能說明'$ result2'包含了什麼嗎? 'print_r($ parsedresult)'給你什麼? – 2012-08-11 15:08:39
回聲調試總是很好地工作:'var_dump($ result2,$ parsedresult,$ emailretrieve);' - 你會得到什麼? – Shi 2012-08-11 15:09:59
$ result2自動打印出以下內容,不需要我回應:{「charge_enabled」:true,「details_submitted」:true,「email」:「[email protected]」,「id」:「xxxx」,「statement_descriptor」 :「xxxx」,「xxxx」:[「USD」]}。 print_r($ parsedresult)返回數字1.它打印出1. – Nochbag 2012-08-11 15:13:20