【发布时间】:2020-01-24 03:23:53
【问题描述】:
我正在尝试解码来自 API 的 JSON 响应并将“serial_no”作为字符串存储在我的代码下方,但我无法获得预期的结果。我做错了什么
来自 API 的 JSON 响应
[
{
"id": 20063,
"transaction_date": "2020-01-24 10:41:031",
"reference_id": "91",
"voucher": [
{
"serial_no": "KFCYQOqW23012024"
}
]
}
]
PHP 代码
/* posting parameters to API */
$post = wp_remote_post( $url, array(
'headers' => array( 'Content-Type' => 'application/x-www-form-urlencoded'),
'body' => $reserve_array
) );
/*Decode JSON response to store in $serial */
$result = json_decode($post);
$serial=$result[0]->voucher[0]->serial_no;
【问题讨论】:
-
$result[0]->voucher[0]->serial_no? -
@dibery 我试过了,但是 $serial 为空,PHP 代码更新了 FYR