【发布时间】:2018-12-03 12:24:36
【问题描述】:
我有一个 JSON 文件,其中包含一些电影数据:
[{
"title": "Bad Company",
"desc": "------------------------",
"rating": "6.0",
"image": "Psycho-Ex-Girlfriend-Twisted-2018.png",
"url": "master.m3u8",
"category": "اكشن"
}, {
"title": "The Pinch",
"desc": "------------------------",
"rating": "6.1",
"image": "Psycho-Ex-Girlfriend-Twisted-2018.png",
"url": "master.m3u8",
"category": "اكشن , جريمه"
}, {
"title": "Catskill Park",
"desc": "------------------------",
"rating": "6.2",
"image": "Psycho-Ex-Girlfriend-Twisted-2018.png",
"url": "master.m3u8",
"category": "خيال علمي , رعب"
}, {
"title": "Klippers",
"desc": "------------------------",
"rating": "5.3",
"image": "Psycho-Ex-Girlfriend-Twisted-2018.png",
"url": "master.m3u8",
"category": "اثاره , اكشن"
}, {
"title": "Psycho",
"desc": "------------------------",
"rating": "5.6",
"image": "Psycho-Ex-Girlfriend-Twisted-2018.png",
"url": "master.m3u8",
"category": "اثاره , دراما"
}]
我需要将所有标题添加到下拉菜单中,当用户从菜单中选择一个项目时,会显示说明、图像和类别。 通过 php
谁能帮帮我?
我的托盘代码
$url = 'http://localhost/ar.json';
$xx = json_decode(file_get_contents($url));
$data = json_decode($xx, true);
$search='title';
foreach($data['meta_data'] as $d){
if($d['key']==$search){
$found=$d['value'];
break;
}
}
echo $found?$found:"$search not found";
【问题讨论】:
-
您自己有没有尝试过任何事情来达到这个要求?如果是这样,请告诉我们
-
@RiggsFolly 是的,我尝试 foreach 但没有工作,我只是初学者谢谢你的回答:)
-
好的,让我们看看这段代码。它将让我们更好地了解您实际在做什么以及使用什么语言
-
$url = 'localhost/ar.json'; $xx = json_decode(file_get_contents($url)); $data = json_decode($xx, true); $搜索='标题'; foreach($data['meta_data'] as $d){ if($d['key']==$search){ $found=$d['value'];休息; } } echo $found?$found:"$search not found";
-
使用问题下方的edit 链接将其添加到您的问题中。没有人可以阅读评论中的代码