我有一个格式如下的JSON文件
{
"Hospital": [
"Hospital One",
"Hospital two",
"Hospital three",
"Hospital four"
],
"School": [
"School One",
"School two",
"School three",
"School four"
],
"Shop": [
"Shop One",
"Shop two",
"Shop three",
"Shop four",
]
}
现在假设我想在医院中获取清单。我该如何获取 请让我知道。
我正在按以下方式使用CURL进行数据访问。
$url = //particularURL ;
$ch = curl_init() ;
curl_setopt($ch, CURLOPT_URL, $url) ;
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$users_result = curl_exec($ch);
if(curl_error($ch)){
echo 'Request Error:' . curl_error($ch);
}
curl_close($ch) ;
// echo $users_result;
$data = json_decode($users_result, true) ;
foreach ($data as $users) {
echo $users["Hospital"] ;
}
但是我遇到了错误
通知:未定义索引:第22行的C:\ xampp \ htdocs \ curl \ curl6.php中的医院
3次
真的很感谢任何帮助