I want to change this response to array
This is value what i received via API: "{'db_password': 'TgD31F#4124!'}"
I would like to remove the quotes and only keep TgD31F#4124!
Code Example
$db = Http::get(HERE_URL);
return $db->body(); // received it here "{'db_password': 'TgD31F#4124!'}"
CodePudding user response:
add datatype:json in ajax
then
response.db_password
else, try parsing it to json.
let RESULT = JSON.parse(response) console.log(RESULT.db_password)
CodePudding user response:
You should use json()
method or object()
method on your response variable. API Reference
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.
Usage:
$response = Http::get("www.api.com/...");
$decodedBody = $response->json();
OR
$decodedBody = $response->object();
EDIT: All available methods are listed in the documentation.