がつがつ食う応答からはstdClassオブジェクトを解析する方法

mirali:

こんにちは私は、外部laravelにおけるAPIと、このように私の応答からの応答を取得するためにがつがつ食うが使用します。

{ "status": { "timestamp": "2020-03-31T14:43:38.674Z", "error_code": 0, "error_message": null, "elapsed": 12, "credit_count": 1, "notice": null }, "data": { "BTC": { "id": 1, "name": "Bitcoin", "symbol": "BTC", "slug": "bitcoin", "num_market_pairs": 7673, "date_added": "2013-04-28T00:00:00.000Z", "tags": [ "mineable" ], "max_supply": 21000000, "circulating_supply": 18297137, "total_supply": 18297137, "platform": null, "cmc_rank": 1, "last_updated": "2020-03-31T14:42:42.000Z", "quote": { "USD": { "price": 6483.18973912, "volume_24h": 36336487377.4909, "percent_change_1h": 0.329128, "percent_change_24h": 2.42904, "percent_change_7d": -2.76632, "market_cap": 118623810853.6729, "last_updated": "2020-03-31T14:42:42.000Z" } } } } }

そして、私の機能は次のとおりです。

$currencies = Currency::where('status',1)->get();
        $symbols = array();
        foreach ($currencies as $currency){
           array_push($symbols,$currency->sign);
        }
        $params = [
            'query' => [
                'symbol' => 'btc,ath'
            ]
        ];
        $client = new Client(['headers' => ['Accepts' => 'application/json','X-CMC_PRO_API_KEY'=>'*******-****-****-*****-********']]);
        $response = $client->request('GET', 'https://pro-api.coinmarketcap.com/v1/cryptocurrency/quotes/latest',$params);
        $res = $response->getBody();
        echo $res;

どのように私は、応答を解析し、特定の通貨を取得するforeachの中でそれを使用することができますか?

ジョシュAlecyan:

使用json_decode()関数

$res = $response->getBody();
$res = json_decode($res);
dd($res);

おすすめ

転載: http://10.200.1.11:23101/article/api/json?id=377804&siteId=1