How to output the value of json object in php

小云云
Release: 2023-03-20 22:42:02
Original
1446 people have browsed it

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 "
"; ?>
Copy after login

<!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>
Copy after login

##json.txt:

{
 "AJAX": "Asynchronous JavaScript and XML",
 "CSS": "Cascading Style Sheets"
}
Copy after login
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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!