php - 从受wordpress保护的数组中获取值
问题描述
我已经使用 API 调用wp_remote_post
并使用wp_remote_retrieve_body
. 但问题是响应正文受 WordPress 保护。我曾尝试使用反射方法和子类方法来检索数据,但失败了。
下面的代码,我用来进行 API 调用和检索数据。
$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>';
}
现在我收到这些错误。
get_object_vars() 期望参数 1 是对象,给定 null
未定义的属性:my_request_utility::$MenuList
为 foreach() 提供的参数无效
请帮我。我已经用不同的方法尝试了三天,但失败了。
解决方案
推荐阅读
- android - Kotlin 使用 SpannableString 设置两种不同的文本样式来动态更改文本视图中的文本
- c++ - 如何使类方法成为协程?
- r - 在同一管道中引用动态命名的列?
- three.js - Three.js Curve.getPoint() 返回世界坐标
- php - RouteNotFoundException 与资源控制器
- python - 具有多个随机数生成器(rng)的脚本的通用随机种子?
- java - 如何在 Spring Boot 中使用带有非字符串查询参数的 RestTemplate?
- ruby-on-rails - will_paginate gem boot_strap 问题
- filesystems - 如何使用逻辑应用程序文件系统和电子邮件通知
- java - com.sun HttpContext 处理程序被多次调用