检索卷曲信息json_decode

问题描述:

我连接到通过电子商务应用程序的命令行中执行以下操作:检索卷曲信息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上的东西,但没有一个能够工作。

+0

你能说明'$ result2'包含了什么吗? 'print_r($ parsedresult)'给你什么? – 2012-08-11 15:08:39

+0

回声调试总是很好地工作:'var_dump($ result2,$ parsedresult,$ emailretrieve);' - 你会得到什么? – Shi 2012-08-11 15:09:59

+0

$ 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

您应该设置选项CURLOPT_RETURNTRANSFER(在http://php.net/curl_exec中提到)来获取结果。现在,你只会得到“成功”或“失败”的结果。

+0

谢谢你的工作! – Nochbag 2012-08-11 15:27:11

+2

@Nochbag:你看到我们如何分析问题并追踪它?有问题的var_dump()变量并问自己:“该值有意义吗?是否有预期?”如果您以“否”回答,请打开手册并开始阅读。哦,如果你自己接受了答案,请在Stack Overflow上也这样做。谢谢。 – Shi 2012-08-11 15:33:15

+1

@Nochbag不接受此答案的任何特定原因?只有当他人知道什么是有效的,什么没有成功时,其他人才会觉得有帮助。 – 2012-08-11 18:05:52