本文主要和大家分享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:
立即学习“PHP免费学习笔记(深入)”;
Easily find JSON paths within JSON objects using our intuitive Json Path Finder
30
{
"AJAX": "Asynchronous JavaScript and XML",
"CSS": "Cascading Style Sheets"
}相关推荐:
web前端开发 - PHP输出json到web无法正常显示中文
以上就是php如何输出json对象的值的详细内容,更多请关注php中文网其它相关文章!
PHP怎么学习?PHP怎么入门?PHP在哪学?PHP怎么学才快?不用担心,这里为大家提供了PHP速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号