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>
<!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>
json.txt:
{ "AJAX": "Asynchronous JavaScript and XML", "CSS": "Cascading Style Sheets" }
相关推荐
MXstudying 2020-09-05
WasteLand 2020-09-15
<?php. if (!empty($_POST)) {. $data1 = $_POST["data1"];$data2 = $_POST["data2"];$fuhao = $_POST["fuh
mathchao 2020-09-15
zyyjay 2020-11-09
xuebingnan 2020-11-05
samtrue 2020-11-22
stefan0 2020-11-22
yifangs 2020-10-13
songshijiazuaa 2020-09-24
hebiwtc 2020-09-18
天步 2020-09-17
83911535 2020-11-13
whatsyourname 2020-11-13
zhouyuqi 2020-11-10
Noneyes 2020-11-10
mathchao 2020-10-28
王志龙 2020-10-28