Blogger Information
Blog 142
fans 5
comment 0
visits 130042
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
php中输出json对象的值(实现方法)
php开发大牛
Original
844 people have browsed it

实例如下所示:

<!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'];
}
?>
www.ablman.com
</body>
</html>

json.txt:

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


Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post