PHP:阅读和解析嵌套的JSON文件
我想将JSON文件用作一种数据库。在其中,我对文件名进行了分类,现在我想通过PHP阅读它们。
{
"settings": {
"prefix": "pix",
"folder": "files/jpg",
"delimiter": "-",
"extension": "jpg"
},
"category": {
"art": {
"painting": {
"1999": ["paint1","paint2","paint3"],
"2000": ["paint4","paint5"]
},
"drawing": {
"1995": ["sketch1","sketch2","sketch3"],
"2012": ["sketch4","sketch5"]
}
},
"project": {
"website": {
"2016": ["web1","web2","web3"]
}
}
}
}
这就是我有多远的范围:
$db = json_decode(file_get_contents("json/_database.json"), true);
$test1 = $db["category"]["art"]["painting"]["2000"];
var_dump($test1);
我想获取以下数据:
- 将所有类别的关键名称作为数组:“ art”,“ project”,“ project”
- 获取所有子类别的关键名称'art'作为一个数组:“绘画”,“绘画”
- 从1995年从子类别“绘图”中获取所有值,作为数组:“ Sketch1”,“ Sketch2”,“ Sketch2”,“ Sketch3”
我知道已经有关于此类问题的问题,但是我无法将答案应用于我的案件中。我将感谢语法符号的示例,然后我可以适应其他情况。
I want to use a json file as a kind of database. In it I have categorized file names and now I want to read them via PHP.
{
"settings": {
"prefix": "pix",
"folder": "files/jpg",
"delimiter": "-",
"extension": "jpg"
},
"category": {
"art": {
"painting": {
"1999": ["paint1","paint2","paint3"],
"2000": ["paint4","paint5"]
},
"drawing": {
"1995": ["sketch1","sketch2","sketch3"],
"2012": ["sketch4","sketch5"]
}
},
"project": {
"website": {
"2016": ["web1","web2","web3"]
}
}
}
}
This is how far I got:
$db = json_decode(file_get_contents("json/_database.json"), true);
$test1 = $db["category"]["art"]["painting"]["2000"];
var_dump($test1);
I would like to get the following data:
- get all category key names as an array: "art", "project"
- get all subcategory key names of 'art' as an array: "painting", "drawing"
- get all values from subcategory 'drawing' in the year 1995 as an array: "sketch1", "sketch2", "sketch3"
I know there are already questions about such problems, but I could not apply the answers to my case. I would be grateful for examples of syntax notation, which I can then adapt to other cases.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
1。:2。:3
。:
1.:
2.:
3.: