我想將此回應更改為陣列
這是我通過 API 收到的值:"{'db_password': 'TgD31F#4124!'}"
我想洗掉引號并只保留TgD31F#4124!
代碼示例
$db = Http::get(HERE_URL);
return $db->body(); // received it here "{'db_password': 'TgD31F#4124!'}"
uj5u.com熱心網友回復:
在ajax中添加資料型別:json然后
response.db_password
否則,嘗試將其決議為 json。
let RESULT = JSON.parse(response) console.log(RESULT.db_password)
uj5u.com熱心網友回復:
您應該在回應變數上使用json()方法或object()方法。API 參考
json method: Get the JSON decoded body of the response as an array or scalar value.
object method: Get the JSON decoded body of the response as an array or scalar value.
用法:
$response = Http::get("www.api.com/...");
$decodedBody = $response->json();
或者
$decodedBody = $response->object();
編輯:所有可用的方法都列在檔案中。
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/324332.html
