数组格式化字符串php curl

时间:2016-06-15 11:35:13

标签: php json curl

我正在使用curl来获取eventbrite api的响应。我有以下代码响应我格式化为json的字符串。我希望它是一个json响应,所以我可以获得所需的数据。

$ch = curl_init();
curl_setopt ($ch, CURLOPT_URL, "https://www.eventbriteapi.com/v3/categories/103/?token=5TYIZLHG7YG6N73RAUHL");
curl_setopt ($ch, CURLOPT_HEADER, 0);
$result = curl_exec ($ch);
curl_close ($ch);
echo json_decode($result, true);

2 个答案:

答案 0 :(得分:1)

以下是解决问题的代码。

$homepage = file_get_contents('https://www.eventbriteapi.com/v3/categories/103/?token=5TYIZL‌​HG7YG6N73RAUHL');
$result = json_decode($homepage);
var_dump($result->name);

答案 1 :(得分:0)

在此代码中,您正在解码JSON,然后回显可能使其再次返回String的对象。

尝试var_dump( json_decode($result) );

因为json_decode($result)会生成对象,如果你试图回显对象,它会在该对象上调用__toString方法,这样你就无处可去了