后台需要通过城市查找区号,考虑到城市数据不多,下载了个json文件,本地读取查找。
一查,结构都是js的ajax读json,getJson。php的思路还是曲线救国:读取成字符串,然后json_encode转成json格式,代码部分如下。
<?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]);
}
}
?>
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。