将json解码为php变量

编程入门 行业动态 更新时间:2024-10-24 22:21:42
本文介绍了将json解码为php变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在尝试将JSON结果的内容转换为php变量.我正在使用的代码是:

I am trying to get the contents of a JSON result into php variables. The code I am using is:

$request = json_decode(file_get_contents("api.sunrise-sunset/json?lat=51.507351&lng=-0.127758&date=today"), true);

JSON调用的输出如下所示:

The output of the JSON call looks like this:

array(2) { ["results"]=> array(10) { ["sunrise"]=> string(10) "4:21:35 AM" ["sunset"]=> string(10) "7:32:34 PM" ["solar_noon"]=> string(11) "11:57:04 AM" ["day_length"]=> string(8) "15:10:59" ["civil_twilight_begin"]=> string(10) "3:42:08 AM" ["civil_twilight_end"]=> string(10) "8:12:01 PM" ["nautical_twilight_begin"]=> string(10) "2:49:55 AM" ["nautical_twilight_end"]=> string(10) "9:04:14 PM" ["astronomical_twilight_begin"]=> string(10) "1:41:12 AM" ["astronomical_twilight_end"]=> string(11) "10:12:57 PM" } ["status"]=> string(2) "OK" }

如何将日出"时间和日落"时间转换为php变量$ SunRiseTime和$ SunSetTime;

How can I get the "sunrise" time and the "sunset" times into php variables $SunRiseTime and $SunSetTime;

非常感谢您抽出宝贵的时间.

Many thanks in advance for your time.

推荐答案

简单而直接.

<?php ini_set('display_errors', 1); $json = file_get_contents("api.sunrise-sunset/json?lat=51.507351&lng=-0.127758&date=today"); $array=json_decode($json,true); echo $SunRiseTime=$array["results"]["sunrise"]; echo $SunSetTime=$array["results"]["sunset"];

输出:4:21:35 AM 7:32:34 PM

更多推荐

将json解码为php变量

本文发布于:2023-08-03 08:08:32,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1285494.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:变量   json   php

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!