有这个么一个json格式个文件 x.json
现在 php中想读取json文件内容并按要求查找丛中的item
例如:通过A03 输出 dkey 的值
该怎么查找对应输出呢?求教!
出错
里面有2个文件夹。其中这个文件名是:finishing,是我项目还没有请求后台的数据的模拟写法。请求后台数据之后,瀑布流的js有一点点变化,放在文件名是:finished。变化在于需要穿参数到后台,和填充的内容都用后台的数据填充。看自己项目需求来。由于chrome模拟器是不允许读取本地文件json的,所以如果你要进行测试,在hbuilder打开项目就可以看到效果啦,或者是火狐浏览器。
92
立即学习“PHP免费学习笔记(深入)”;
有这个么一个json格式个文件 x.json
现在 php中想读取json文件内容并按要求查找丛中的item
例如:通过A03 输出 dkey 的值
该怎么查找对应输出呢?求教!
出错
立即学习“PHP免费学习笔记(深入)”;
你的json文件有bom头,
<code>$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;
}
}
</code>
var_dump(json_decode($json));
先把值全打印出来,就知道该怎么调用了
PHP怎么学习?PHP怎么入门?PHP在哪学?PHP怎么学才快?不用担心,这里为大家提供了PHP速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号