后台须要经过城市查找区号,考虑到城市数据很少,下载了个json文件,本地读取查找。
一查,结构都是js的ajax读json,getJson。php的思路仍是曲线救国:读取成字符串,而后json_encode转成json格式,代码部分以下。php
<?php // Read JSON file $json = file_get_contents('./student_data.json'); //Decode JSON $json_data = json_decode($json,true); //Traverse array and get the data for students aged less than 20 foreach ($json_data as $key1 => $value1) { if($json_data[$key1]["Age"] < 20){ print_r($json_data[$key1]); } } ?>