2 回答

TA貢獻1798條經(jīng)驗 獲得超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條經(jīng)驗 獲得超8個贊
您對對象和數(shù)組感到困惑
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
}
}
}
}
}
確保您使用好的標簽。虛擬占位符可能沒問題,但它使跟蹤錯誤變得非常困難。我假設(shè)您想檢查他們是否擁有使用數(shù)據(jù)庫、使用 PDO 的權(quán)限?
// 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 對象中包含數(shù)組,也可以在數(shù)組中包含 JSON 對象。您訪問它們的方式有所不同。
- 2 回答
- 0 關(guān)注
- 129 瀏覽
添加回答
舉報