我正在尝试使用PHP和cURL调用易趣的Shopping API,并以JSON格式返回响应。当我把URL直接放在浏览器中时,它是有效的,但它不在PHP中。我不想使用XML。JSON更容易。有什么建议吗?
$Url ="http://open.api.ebay.com/shopping?callname=GetMultipleItems&responseencoding=JSON&appid=MyAppId&siteid=0&version=525&ItemID=290585620456,290683575886&IncludeSelector=Details,ShippingCosts,Variations";
//check if you have curl loaded
if(!function_exists("curl_init")) die("cURL extension is not installed");
$ch=curl_init($Url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$r=curl_exec($ch);
curl_close($ch);
var_dump($r);
您应该使用
json_encode($response_string);
这将把响应字符串解析为json对象。
如果您想要基本数组而不是json对象,那么使用
json_decode($responce_str, true);
这将返回一个关联数组。