【发布时间】:2019-10-09 04:06:19
【问题描述】:
我正在尝试在 php 的 foreach 循环中打印以下 json 数据。谁能告诉我我该怎么做?我搜索了很多,但没有任何效果。 我从 coinmarket api 获取这些数据并使用以下方法打印此代码: 但未能分别获取每个值。
$curl = curl_init(); // Get cURL resource
// Set cURL options
curl_setopt_array($curl, array(
CURLOPT_URL => $request, // set the request URL
CURLOPT_HTTPHEADER => $headers, // set the headers
CURLOPT_RETURNTRANSFER => 1 // ask for raw response instead of bool
));
$response = curl_exec($curl); // Send the request, save the response
print_r(json_decode($response));
下面是我想在 foreach 循环中使用的代码:
stdClass Object ( [status] => stdClass Object ( [timestamp] => 2019-10-09T03:13:30.051Z [error_code] => 0 [error_message] => [elapsed] => 9 [credit_count] => 1 [notice] => ) [data] => stdClass Object ( [BTC] => stdClass Object ( [id] => 1 [name] => Bitcoin [symbol] => BTC [slug] => bitcoin [num_market_pairs] => 7935 [date_added] => 2013-04-28T00:00:00.000Z [tags] => Array ( [0] => mineable ) [max_supply] => 21000000 [circulating_supply] => 17981825 [total_supply] => 17981825 [platform] => [cmc_rank] => 1 [last_updated] => 2019-10-09T03:12:33.000Z [quote] => stdClass Object ( [USD] => stdClass Object ( [price] => 8195.0290967 [volume_24h] => 14981665979.667 [percent_change_1h] => -0.224992 [percent_change_24h] => -1.35388 [percent_change_7d] => -1.38135 [market_cap] => 147361579086.77 [last_updated] => 2019-10-09T03:12:33.000Z ) ) ) ) )
【问题讨论】: