为了账号安全,请及时绑定邮箱和手机立即绑定

使用PHP从[JSON]文件获取数据

使用PHP从[JSON]文件获取数据

PHP
慕尼黑8549860 2019-09-20 17:06:13
我正在尝试使用PHP从以下JSON文件中获取数据。我特别想要“temperatureMin”和“temperatureMax”。这可能很简单,但我不知道该怎么做。我坚持在file_get_contents(“file.json”)之后做什么。一些帮助将不胜感激!{    "daily": {        "summary": "No precipitation for the week; temperatures rising to 6° on Tuesday.",        "icon": "clear-day",        "data": [            {                "time": 1383458400,                "summary": "Mostly cloudy throughout the day.",                "icon": "partly-cloudy-day",                "sunriseTime": 1383491266,                "sunsetTime": 1383523844,                "temperatureMin": -3.46,                "temperatureMinTime": 1383544800,                "temperatureMax": -1.12,                "temperatureMaxTime": 1383458400,            }        ]    }}
查看完整描述

3 回答

?
绝地无双

TA贡献1946条经验 获得超4个赞

使用json_decode将您的JSON转换为PHP数组。例:


$json = '{"a":"b"}';

$array = json_decode($json, true);

echo $array['a']; // b


查看完整回答
反对 回复 2019-09-20
?
慕仙森

TA贡献1827条经验 获得超7个赞

Try:

$data = file_get_contents ("file.json");

        $json = json_decode($data, true);

        foreach ($json as $key => $value) {

            if (!is_array($value)) {

                echo $key . '=>' . $value . '<br/>';

            } else {

                foreach ($value as $key => $val) {

                    echo $key . '=>' . $val . '<br/>';

                }

            }

        }


查看完整回答
反对 回复 2019-09-20
  • 3 回答
  • 0 关注
  • 494 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信