下面小编就为大家分享一篇php中输出json对象的值(实现方法),具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧
实例如下所示:
<!DOCTYPE html>
<html>
<body>
<?php
$json = '{"report":{"date":"2012-04-10","content":"abcdefght"}}';
$arr = (array) json_decode($json,true);
echo '当前日期是:'. $arr['report']['date'];
echo "<br/>";
echo '<pre>';
print_r($arr);
echo '</pre>';
foreach($arr as $arrvalue)
{
foreach($arrvalue as $key=>$value)
{
echo "[$key] = $value <br />";
}
}
echo "<br/>";
?>
</body>
</html>
<!DOCTYPE html>
<html>
<body>
<?php
$file_exists = file_exists("json.txt");
if( $file_exists ){
$myfile = fopen("json.txt", "r") or die("");
$content = fread($myfile,filesize("json.txt"));
fclose($myfile);
echo $content;
echo "<br/>";
$arr=(array)json_decode($content,true);
echo $arr['CSS'];
echo "<br/>";
echo $arr['AJAX'];
}
?>
</body>
</html>
json.txt:
{
"AJAX": "Asynchronous JavaScript and XML",
"CSS": "Cascading Style Sheets"
}
以上这篇php中输出json对象的值(实现方法)就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持编程学习网。
沃梦达教程
本文标题为:php中输出json对象的值(实现方法)
猜你喜欢
- PHP仿tp实现mvc框架基本设计思路与实现方法分析 2022-10-18
- laravel实现按月或天或小时统计mysql数据的方法 2023-02-22
- PHP简单实现二维数组的矩阵转置操作示例 2022-10-02
- 用nohup命令实现PHP的多进程 2023-09-02
- laravel通用化的CURD的实现 2023-03-17
- PHP中PDO事务处理操作示例 2022-10-15
- Laravel balde模板文件中判断数据为空方法 2023-08-30
- windows下9款一键快速搭建PHP本地运行环境的好工具(含php7.0环境) 2023-09-02
- php微信公众号开发之秒杀 2022-11-23
- PHP实现微信支付(jsapi支付)流程步骤详解 2022-10-09