我有以下陣列
$folder_data = array(
"title" => "Testing API Creation",
"description" => "Testing the Wrike API by creating this folder.",
"project" => array(
"status" => "OnHold",
"startDate" => "2022-05-19",
"endDate" => "2022-06-19",
"contractType" => "Billable",
"budget" => 100
)
);
當我通過 http_build_query() 運行它時,它給了我這個(用于清楚起見的 urldecode()):
title=Testing API Creation&description=Testing the Wrike API by creating this folder.&project[status]=OnHold&project[startDate]=2022-05-19&project[endDate]=2022-06-19&project[contractType]=Billable&project[budget]=100
API 拋出一個錯誤,指出 project[status] 是一個無效引數 API 檔案在 curl 示例中給出了這個。您可以看到“專案”的資料已分組:
title=Test folder&description=Test description&project={"ownerIds":["KUFK5PMF"],"startDate":"2021-10-19","endDate":"2021-10-26","contractType":"Billable","budget":100}
我猜他們將查詢嵌套到物件中?我將如何使用我的 PHP 陣列來做到這一點?我嘗試了一個有人做過的遞回函式,但它也沒有給我它正在尋找的東西。
任何幫助表示贊賞!謝謝!
uj5u.com熱心網友回復:
該project引數在他們的示例中是 JSON,因此請使用它json_encode()來創建它。
$folder_data = array(
"title" => "Testing API Creation",
"description" => "Testing the Wrike API by creating this folder.",
"project" => json_encode(array(
"status" => "OnHold",
"startDate" => "2022-05-19",
"endDate" => "2022-06-19",
"contractType" => "Billable",
"budget" => 100
))
);
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/473521.html
下一篇:我怎樣才能旋轉這個陣列?
