这是我的多维数组..我知道如何将数组编码为 json 但没有得到实际的 json 预期的 json 结果
array (
1 =>
array (
'text' => 'Dashboard',
'spriteCssClass' => 'rootfolder',
'expanded' => 'true',
'id' => '1',
'item_name' => 'Dashboard',
'menu_type' => 'item',
'parent' => '0',
'items' =>
array (
9 =>
array (
'text' => 'Application',
'spriteCssClass' => 'html',
'id' => '9',
'item_name' => 'Application',
'menu_type' => 'header',
'parent' => '1',
'items' =>
array (
),
),
),
),
)
将其编码为 json 后,我得到以下结果
对于编码,我使用了 json_encode($array);
{
"1": {
"text": "Dashboard",
"spriteCssClass": "rootfolder",
"expanded": "true",
"id": "1",
"item_name": "Dashboard",
"menu_type": "item",
"parent": "0",
"items": {
"9": {
"text": "Application",
"spriteCssClass": "html",
"id": "9",
"item_name": "Application",
"menu_type": "header",
"parent": "1",
"items": {}
}
}}}
我想要以下编码的json
{
"text": "Dashboard",
"spriteCssClass": "rootfolder",
"expanded": "true",
"id": "1",
"item_name": "Dashboard",
"menu_type": "item",
"parent": "0",
"items": [
{
"text": "Application",
"spriteCssClass": "html",
"id": "9",
"item_name": "Application",
"menu_type": "header",
"parent": "1",
"items": {}
}]
}
我几乎尝试了一切,但没有得到我预期的 json 结果 我想从 json 中删除数组索引,如“1”{ 并且还想在每个项目之后添加“[”这个:列
最佳答案
看起来你只是想 json_encode($yourData[1])
而不是 json_encode($yourData)
...
关于php - 多维数组转json,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22043098/