有这个么一个json格式个文件 x.json
现在 php中想读取json文件内容并按要求查找丛中的item
例如:通过a03 输出 dkey 的值
该怎么查找对应输出呢?求教!
出错
回复内容:
有这个么一个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));
先把值全打印出来,就知道该怎么调用了