【问题标题】:JSON API response from endpoint retrieve value and decode来自端点的 JSON API 响应检索值并解码
【发布时间】:2017-06-16 03:38:30
【问题描述】:

端点发送一个

回应

WP_HTTP_Requests_Response Object
(
[response:protected] => Requests_Response Object
(
[body] => {“status”:”success”,”result”:”112″,”code”:200}

我试图获取“result:”112”

有办法找回吗?

谢谢。 ????

【问题讨论】:

标签: php json wordpress api


【解决方案1】:

请参阅此处的文档:https://developer.wordpress.org/reference/classes/wp_http_requests_response/

假设您得到的响应 (WP_HTTP_Requests_Response) 存储在一个名为 $response 的变量中,您应该这样做:

$response_data = json_decode($response->get_response_object()->body);
$result = $response_data->result; // this is the result you want

【讨论】:

  • 您好,我收到的回复是通过使用插件 3rd-party-integration 的电子邮件。我不确定如何将它放在变量上,因为我不确定从哪里获得它,因为它是通过电子邮件发送的调试通知。对不起。谢谢!
猜你喜欢
  • 2018-10-21
  • 1970-01-01
  • 2017-06-14
  • 2021-07-26
  • 2016-03-29
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2023-01-12
相关资源
最近更新 更多