Home > Backend Development > PHP Tutorial > What methods are there in php to output the value of a json object?

What methods are there in php to output the value of a json object?

php中世界最好的语言
Release: 2023-03-26 15:24:02
Original
1596 people have browsed it

This time I will show you what methods PHP can use to output the value of a json object. What are the precautions for PHP to output the value of a json object? The following is a practical case, let's take a look.

An 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 '<pre class="brush:php;toolbar:false">';
 print_r($arr);
echo '
';     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['CSS'];
 echo "<br/>";
 echo $arr['AJAX'];
}
?>
 
</body>
</html>
Copy after login

json.txt:

{
 "AJAX": "Asynchronous JavaScript and XML",
 "CSS": "Cascading Style Sheets"
}
Copy after login
I believe you have mastered the method after reading the case in this article. For more exciting information, please pay attention to other related articles on the php Chinese website!

Recommended reading:

A brief discussion on how to use pack and unpack in PHP

Operation of PHP associative arrays and index arrays Detailed explanation of steps

The above is the detailed content of What methods are there in php to output the value of a json object?. 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