时间:2021-07-01 10:21:17 帮助过:31人阅读
实例如下所示:
<!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" }
相信看了本文案例你已经掌握了方法,更多精彩请关注Gxl网其它相关文章!
推荐阅读:
浅谈PHP中pack、unpack使用方法详解
操作php关联数组与索引数组步骤详解
以上就是php有哪些方法可以输出json对象的值的详细内容,更多请关注Gxl网其它相关文章!