doushang1890 2018-07-14 06:16
浏览 31

从数组中获取哪些数据受wordpress保护

I have made an API call using wp_remote_post and retrieved the values using wp_remote_retrieve_body. But the problem is the response body is protected by WordPress. I have tried using reflection method and subclass methods to retrieve the data but failed.

Below code, I have used to make API call and retrieve data.

$response = wp_remote_post ( 'https://apiurl.com?APIKEY='."$api_key".'', $args );
    $response = json_decode(wp_remote_retrieve_body($response), true);

    class my_request_utility {
        protected $response;

        public function test() {
        var_dump(get_object_vars($this->response));
    }
    }
    $my_array = new my_request_utility;
    var_dump(get_object_vars($my_array));
    $my_array->test();
    $currencyData = wp_remote_retrieve_body( $currency );
    $responceData = $my_array;

    $str = '';
    foreach ($responceData->MenuList as $Item)
    {
        $str .= '<table width="100%" height="auto" border="0px solid #FFFFFF">
        <tr>
        <td width="80%" class="cat">'.$Item['Name'].'</td>
        <td width="20%" align="center" class="cat">
          <a target="_blank" href="'.$ulr.'">ORDER</a>
        </td>
        </tr>';
        foreach($Item['Item'] as $Value)
        {
            $str .= '<tr>
                      <td class="item" width="80%">'.$Value['Price'].'</td>
                      <td class="item" align="center" width="20%"><b>'.$Value['Price'].'</b></td>
                  </tr>';
        }
        $str .= '</table>';    
    }

Now I am Getting these Errors.

get_object_vars() expects parameter 1 to be object, null given

Undefined property: my_request_utility::$MenuList

Invalid argument supplied for foreach()

Please Help me. I have been trying for three days with different methods but failing.

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 谁有RH342练习环境
    • ¥15 STM32F407 DMA中断问题
    • ¥15 uniapp连接阿里云无法发布消息和订阅
    • ¥25 麦当劳点餐系统代码纠错
    • ¥15 轮班监督委员会问题。
    • ¥15 基于作物生长模型下,有限水资源的最大化粮食产量的资源优化模型建立
    • ¥20 关于变压器的具体案例分析
    • ¥15 生成的QRCode圖片加上下載按鈕
    • ¥15 板材切割优化算法,数学建模,python,lingo
    • ¥15 科来模拟ARP欺骗困惑求解