第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

我怎么能用PHP編寫一個看起來像這個(嵌套的JSON結(jié)構(gòu))的JSON文件?

我怎么能用PHP編寫一個看起來像這個(嵌套的JSON結(jié)構(gòu))的JSON文件?

PHP
繁華開滿天機 2022-09-30 16:21:35
我想用PHP編寫一個“嵌套”的JSON結(jié)構(gòu) 下面看看結(jié)果應(yīng)該是什么樣子:(手動編寫 - 可以在JS中讀取而不會出錯:)){    "general": {        "language": "English",        "workingmode": "Normal"    },    "scene": [{          "id": 0,          "calendar_event": "urlaub",          "element": [              {              "device": "boiler1",              "active_state": "nothing",              "hybernation_state": "off",              "calendar_name": "roomlink4"              },              {              "device": "boiler1",              "active_state": "on",              "hybernation_state": "off",              "calendar_name": "roomlink4"              }          ]        },        {          "id": 1,          "calendar_event": "urlaub",          "element": [              {              "device": "boiler1",              "active_state": "on",              "hybernation_state": "off",              "calendar_name": "roomlink4"              },              {              "device": "boiler1",              "active_state": "on",              "hybernation_state": "off",              "calendar_name": "roomlink4"              }          ]        }    ]}這是我到目前為止的代碼:$knxGenSet = (object) [    'general' => (object) [],    'scene' => []    //Now i Struggle with this part, i cannot accomplish it to add "element" so that it is nested inside of "scene"];//creating structure for "general"$knxGenSet->general->language = $_POST["langsetts"];$knxGenSet->general->workingmode = $_POST["wmodesetts"];//second part which i struggle with  $knxGenSet->scene[] = (object) [      //creating structure for "scene"      'id' => 0,      'calendar_event' => "anything"      //Struggle: cannot get it right to add "element"-array which consists of 4 more String to the structure  ];我確實設(shè)法添加了“常規(guī)”選項卡和“場景”的一部分,但我沒有設(shè)法將“元素”數(shù)組的部分添加到“場景”順便說一句,我可以用JS閱讀這個json格式提前致謝(json領(lǐng)土上的新手! :()
查看完整描述

1 回答

?
一只萌萌小番薯

TA貢獻1795條經(jīng)驗 獲得超7個贊

你錯過了一些小的關(guān)鍵點


$knxGenSet = (object) [

    'general' => (object) ["language" => $_POST["langsetts"], 

    "workingmode" => $_POST["wmodesetts"]

]

];


for($j=0; $j<2; $j++) {

    $scene = (object) [

        'id' => $j,

        'calendar_event' => $_POST["calendarevent" . $j]

    ];


    for($ii=0; $ii<2; $ii++) {

        $scene->element[] = (object) [

            "device" => "boiler".$ii,

            "active_state"=> "on",

            "hybernation_state"=> "off",

            "calendar_name"=> "roomlink4"

         ];

    }

    $knxGenSet->scene[] = $scene;

}


print json_encode($knxGenSet);


輸出


{

    "general": {

        "language": null,

        "workingmode": null

    },

    "scene": [{

        "id": 0,

        "calendar_event": null,

        "element": [{

            "device": "boiler0",

            "active_state": "on",

            "hybernation_state": "off",

            "calendar_name": "roomlink4"

        }, {

            "device": "boiler1",

            "active_state": "on",

            "hybernation_state": "off",

            "calendar_name": "roomlink4"

        }]

    }, {

        "id": 1,

        "calendar_event": null,

        "element": [{

            "device": "boiler0",

            "active_state": "on",

            "hybernation_state": "off",

            "calendar_name": "roomlink4"

        }, {

            "device": "boiler1",

            "active_state": "on",

            "hybernation_state": "off",

            "calendar_name": "roomlink4"

        }]

    }]

}


查看完整回答
反對 回復(fù) 2022-09-30
  • 1 回答
  • 0 關(guān)注
  • 93 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號