So analysieren Sie das stdClass-Objekt aus der Guzzle-AntwortPhp

PHP-Programmierer chatten hier
Anonymous
 So analysieren Sie das stdClass-Objekt aus der Guzzle-Antwort

Post by Anonymous »

Hallo, ich verwende Guzzle, um eine Antwort von einer externen API in Laravel zu erhalten, und meine Antwort sieht so aus:

{ "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" } } } } }


und meine Funktion ist:

$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/cr ... t',$params);
$res = $response->getBody();
echo $res;


Wie kann ich die Antwort analysieren und in foreach verwenden, um eine bestimmte Währung zu erhalten?

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post