2 回答

TA贡献1798条经验 获得超7个赞
这是你想要的?
<?php
$jsonData = '{
"users": [
{
"userid": 1,
"username": "Admin",
"usermail": "admin@admin.com",
"authority": [
{
"authorityid": 1,
"authoritytext": "Admin",
"mission": [
{
"permission": "add"
},
{
"permission": "delete"
},
{
"permission": "move"
}
]
},
{
"authorityid": 1,
"authoritytext": "Super Admin",
"mission": [
{
"permission": "no add"
},
{
"permission": "no delete"
},
{
"permission": "only moderate"
}
]
}
]
}
]
}';
$data = json_decode($jsonData);
echo($data->users[0]->authority[0]->mission[0]->permission);

TA贡献1789条经验 获得超8个赞
您对对象和数组感到困惑
foreach($result->users as $currentUser){
$auths = $currentUser->authority;
foreach($auths as $currentAuth){
foreach($currentAuth->mission as $permission){
foreach($permission as $positionLabel => $permissionValue){
if($permissionValue == "add"){
// code here
}
}
}
}
}
确保您使用好的标签。虚拟占位符可能没问题,但它使跟踪错误变得非常困难。我假设您想检查他们是否拥有使用数据库、使用 PDO 的权限?
// array
$arr = ["this", "is", "an", "array"];
echo $arr[0] // prints out the word this.
$json = { "attribute": "value"}
echo $json->attribute // prints out the word value.
您可以在 JSON 对象中包含数组,也可以在数组中包含 JSON 对象。您访问它们的方式有所不同。
- 2 回答
- 0 关注
- 100 浏览
添加回答
举报