这次给大家带来php中如何输出json对象,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中文网其它相关文章!
推荐阅读:
动态WEB网站中的PHP和MySQL详细反映实际程序的需求,仔细地探讨外部数据的验证(例如信用卡卡号的格式)、用户登录以及如何使用模板建立网页的标准外观。动态WEB网站中的PHP和MySQL的内容不仅仅是这些。书中还提到如何串联JavaScript与PHP让用户操作时更快、更方便。还有正确处理用户输入错误的方法,让网站看起来更专业。另外还引入大量来自PEAR外挂函数库的强大功能,对常用的、强大的包
508
PHP怎么学习?PHP怎么入门?PHP在哪学?PHP怎么学才快?不用担心,这里为大家提供了PHP速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号