PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Thursday, January 13, 2022

[FIXED] Getting the specific part of a JSON

 January 13, 2022     api, laravel, php     No comments   

Issue

I have an API and I use that API to get the exchange rates.

$client = new \GuzzleHttp\Client();
$res = $client->request('GET', 'https://v6.exchangerate-api.com/v6/3307b104e7b3be179b55050e/latest/USD');
$currency = $res->getBody();

I want to get the conversion_rates data only from the JSON and ignore the rest.

I use Laravel.


Solution

might work

$client = new \GuzzleHttp\Client();
$res = $client->request('GET', 'https://v6.exchangerate-api.com/v6/3307b104e7b3be179b55050e/latest/USD');

$data = $res->getBody()->getContents();
$dataArray = json_decode($data, true);
$rates = $dataArray['conversion_rates'] ?? [];


Answered By - abSiddique
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing