Rumah >pembangunan bahagian belakang >tutorial php >php读取解析json文件,该怎么解决
php读取解析json文件
<?php <br /> $filename = "./js/recommendMenu.json";<br /> $json_string = file_get_contents($filename);<br /> echo print_r($json_string,true); //打印文件的内容<br /> echo "<br>";<br /> <br /> $json2_string='{<br /> "tsnpm":{<br /> "name":"#特色牛排面#",<br /> "score":"(4.7分)",<br /> "price":"¥9.0",<br /> "description":"较劲十足,微辣畅爽。"<br /> },<br /> "mnnrm":{<br /> "name":"#:闽南牛肉面#",<br /> "score":"(4.8分)",<br /> "price":"¥8.5",<br /> "description":"爽滑可口,回味无穷。"<br /> },<br /> "hxncm":{<br /> "name":"#红烧牛杂面#",<br /> "score":"(4.8分)",<br /> "price":"¥8.0",<br /> "description":"清香诱人,五味杂成!"<br /> },<br /> "gwcsgjf":{<br /> "name":"#广味叉烧盖浇饭#",<br /> "score":"(4.7分)",<br /> "price":"¥8.5",<br /> "description":"滋补,养胃、美味、有劲"<br /> },<br /> "xhscd":{<br /> "name":"#西红柿炒蛋#",<br /> "score":"(4.8分)",<br /> "price":"¥2.0",<br /> "description":"口味怡人,物美价廉!"<br /> }<br />}';<br /> $obj=json_decode($json2_string,true);<br /> if (!is_array($obj)) die('no successful');<br /> print_r($obj);<br /> echo '<br>'.$obj['tsnpm']['name'];<br /> ?>