怎么在php中对json对象的值进行输出

怎么在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>

怎么在php中对json对象的值进行输出

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

怎么在php中对json对象的值进行输出

json.txt:

{
 "AJAX": "Asynchronous JavaScript and XML",
 "CSS": "Cascading Style Sheets"
}

关于怎么在php中对json对象的值进行输出就分享到这里了,希望以上内容可以对大家有一定的帮助,可以学到更多知识。如果觉得文章不错,可以把它分享出去让更多的人看到。