解码 JSON 一次并显示数据

问题描述 投票:0回答:0

好吧,从头开始。我有一个 API 链接,我可以从中将数据下载到网站:

<?php
$api = file_get_contents('LINK DO API');
$decoded_json = json_decode($api, true);
$data = $decoded_json['data'];
$dane = $data['temp_and_humidity_ch3']['temperature'];
  
{
  echo $dane['value'].$dane['unit'];
}
?>

它起作用了,一切都显示出来了。问题是我有19个这样的数据要下载和显示。当我插入相同的代码 19 次,仅更改显示的参数时,页面加载时间不到一秒,而不是加载时间将近 8 秒......我不知道如何以仅下载整个内容的方式进行操作一次然后只显示,无需重新解码 JSON。

php json file-get-contents
© www.soinside.com 2019 - 2024. All rights reserved.