小编Abh*_*yap的帖子

如何在不知道键值的情况下在php中读取JSON数据

我需要在php中读取firebase JSON URL然后显示它.我的firebase得到了以下.json数据:

{"dDsdE4AlB7P5YYd4fWbYTQKCLPh1":{"email":"abhi@gmail.com","name":"abhishek"},
 "z1ceiLhdh9YVu7lGnVvqDWoWHFH3":{"email":"ravi@gmail.com","name":"ravish"},
 "ghg76JHG8jhkj7GHGJ763kjhFF45":{"email":"John@gmail.com","name":"John"}}
Run Code Online (Sandbox Code Playgroud)

我可以使用键值访问"name"字段,如下所示: -

$url = 'https://xxxx.firebaseio.com/users.json'; // path to JSON file
$data = file_get_contents($url); // put the contents of the file into a variable
$characters = json_decode($data); // decode the JSON feed

echo $characters->dDsdE4AlB7P5YYd4fWbYTQKCLPh1->name;
Run Code Online (Sandbox Code Playgroud)

现在,如何在不知道键值的情况下访问"名称"字段?因为这些密钥是由firebase自动生成的,可以是任何值.

提前谢谢了!

php json firebase

4
推荐指数
1
解决办法
929
查看次数

标签 统计

firebase ×1

json ×1

php ×1