Home >Backend Development >PHP Tutorial >How to output the value of json object in php

How to output the value of json object in php

小云云
小云云Original
2018-03-09 10:00:111466browse

This article mainly shares with you how to output the value of json object in PHP. I hope it can help you.

The example is as follows:

 <!DOCTYPE html>
<html>
<body>
<?php
 
$json = &#39;{"report":{"date":"2012-04-10","content":"abcdefght"}}&#39;;
 $arr = (array) json_decode($json,true);
 echo &#39;当前日期是:&#39;. $arr[&#39;report&#39;][&#39;date&#39;];
echo "<br/>";
echo &#39;<pre class="brush:php;toolbar:false">&#39;;
 print_r($arr);
echo &#39;
'; foreach($arr as $arrvalue) { foreach($arrvalue as $key=>$value) { echo "[$key] = $value
"; } } echo "
"; ?>

<!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[&#39;CSS&#39;];
 echo "<br/>";
 echo $arr[&#39;AJAX&#39;];
}
?>
 
</body>
</html>

##json.txt:

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


html formatted output JSON

php output json and display Chinese characters in json detailed explanation and examples

Web front-end development - PHP outputs json to the web and cannot display Chinese properly

The above is the detailed content of How to output the value of json object in php. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Previous article:PHP character formattingNext article:PHP character formatting