我正在嘗試從API解碼JSON響應,并將“serial_no”存儲為字符串,位于我的代碼下方,但我無法獲得預期的結果。我做錯了什么嗎來自 API 的 JSON 響應 [ { "id": 20063, "transaction_date": "2020-01-24 10:41:031", "reference_id": "91", "voucher": [ { "serial_no": "KFCYQOqW23012024" } ] } ] 網絡工序代碼/* 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;
1 回答

蕭十郎
TA貢獻1815條經驗 獲得超13個贊
下面的PHP代碼解決了我的問題
$result = json_decode( wp_remote_retrieve_body( $post) ); $serial=$result[0]->voucher[0]->serial_no;
- 1 回答
- 0 關注
- 77 瀏覽
添加回答
舉報
0/150
提交
取消