扫码关注官方订阅号
有这个么一个json格式个文件 x.json
现在 php中想读取json文件内容并按要求查找丛中的item 例如:通过A03 输出 dkey 的值该怎么查找对应输出呢?求教!
出错
业精于勤,荒于嬉;行成于思,毁于随。
你的json文件有bom头,
$json = file_get_contents('Qcode.json'); $arr = json_decode(trim($json, chr(239) . chr(187) . chr(191)), true); $temp = array_column($arr, 'dkey', 'dvalue'); echo $temp['A05']; if (! function_exists('array_column')) { function array_column(array $input, $columnKey, $indexKey = null) { $array = array(); foreach ($input as $value) { if (! isset($value[$columnKey])) { trigger_error("Key \"$columnKey\" does not exist in array"); return false; } if (is_null($indexKey)) { $array[] = $value[$columnKey]; } else { if (! isset($value[$indexKey])) { trigger_error("Key \"$indexKey\" does not exist in array"); return false; } if (! is_scalar($value[$indexKey])) { trigger_error("Key \"$indexKey\" does not contain scalar value"); return false; } $array[$value[$indexKey]] = $value[$columnKey]; } } return $array; } }
var_dump(json_decode($json));
先把值全打印出来,就知道该怎么调用了
微信扫码关注PHP中文网服务号
QQ扫码加入技术交流群
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
PHP学习
技术支持
返回顶部
你的json文件有bom头,
var_dump(json_decode($json));
先把值全打印出来,就知道该怎么调用了