从 currencyconverterapi 打印 JSON 数据
Print JSON data from currencyconverterapi
我正在尝试打印来自货币转换器 API JSON 数据的值。
任何人都可以帮我打印这个值 URL
https://free.currencyconverterapi.com/api/v5/convert?q=USD_IDR&compact=y?
$data = json_decode('{"USD_IDR":{"val":13965}}', TRUE);
var_dump($data["USD_IDR"]["val"]); //int(13965)
你必须使用file_get_contents() along with json_decode()
<?php
$json_data = file_get_contents('https://free.currencyconverterapi.com/api/v5/convert?q=USD_IDR&compact=y');
$array = json_decode($json_data, true);
var_dump($array["USD_IDR"]["val"]);
?>
我已经在本地机器上测试过并且工作正常:-
试试这个:
ob_start();
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,'https://free.currencyconverterapi.com/api/v5/convert?q=USD_IDR&compact=y');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
$jsontoarr = json_decode($response);
echo $jsontoarr->USD_IDR->val;
祝你好运。
我正在尝试打印来自货币转换器 API JSON 数据的值。
任何人都可以帮我打印这个值 URL
https://free.currencyconverterapi.com/api/v5/convert?q=USD_IDR&compact=y?
$data = json_decode('{"USD_IDR":{"val":13965}}', TRUE);
var_dump($data["USD_IDR"]["val"]); //int(13965)
你必须使用file_get_contents() along with json_decode()
<?php
$json_data = file_get_contents('https://free.currencyconverterapi.com/api/v5/convert?q=USD_IDR&compact=y');
$array = json_decode($json_data, true);
var_dump($array["USD_IDR"]["val"]);
?>
我已经在本地机器上测试过并且工作正常:-
试试这个:
ob_start();
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,'https://free.currencyconverterapi.com/api/v5/convert?q=USD_IDR&compact=y');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
$jsontoarr = json_decode($response);
echo $jsontoarr->USD_IDR->val;
祝你好运。