ホーム>source

こんにちは、Kodi Playerからのjson応答に問題があります。channelidやlabelなどの2つの値を抽出する必要があります。

{"id":"libGetChannels","jsonrpc":"2.0","result":{"channels":[{"channel":"BBC
 One HD","channelid":3,"label":"BBC One HD","lastplayed":"2018-08-16"}, 
{"channel":"BBC Two HD","channelid":4,"label":"BBC Two 
HD","lastplayed":"2018-08-16"}],"limits":{"end":2,"start":0,"total":2}}}

Jsonの新人を助けてくれてありがとう

あなたの答え
  • 解決した方法 # 1

       $json = '{"id":"libGetChannels","jsonrpc":"2.0","result":{"channels":[{"channel":"BBC One HD","channelid":3,"label":"BBC One HD","lastplayed":"2018-08-16"},{"channel":"BBC Two HD","channelid":4,"label":"BBC Two HD","lastplayed":"2018-08-16"}],"limits":{"end":2,"start":0,"total":2}}}';
        $array = json_decode($json);
        $channelsArray = [];
        foreach ($array as $value){
            if(is_object($value)){
               foreach ($value->channels as $channel){
                   $channelsArray[] = $channel;
               }
            }
        }
        foreach($channelsArray as $channel){
            echo $channel->channelid;
            echo $channel->label;
        }
    
    

  • 前へ java - JPAクエリ:サブクエリをグループ化条件に結合する
  • 次へ dropbox api - APIを使用してチームフォルダーにグループを追加できない