您的位置:首页 > 编程语言 > PHP开发

php中输出json对象的值(实现方法)

2018-03-07 11:38 411 查看

实例如下所示:

<!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 对象