how can I Select the value of "success" from that json?:
{
"response": {
"success": true,
"groups": [
{
"gid": "3229727"
},
{
"gid": "4408371"
}
]
}
}
Thats my current code:
$result = json_decode ($json);
$success = $result['response'][0]['success'];
echo $success;
Thank you. Regards
Here You go... with a Quick-Test Here:
<?php
$strJson = '{
"response": {
"success": true,
"groups": [
{
"gid": "3229727"
},
{
"gid": "4408371"
}
]
}
}';
$data = json_decode($strJson);
$success = $data->response->success;
$groups = $data->response->groups;
var_dump($data->response->success); //<== YIELDS:: boolean true
var_dump($groups[0]->gid); //<== YIELDS:: string '3229727' (length=7)
var_dump($groups[1]->gid); //<== YIELDS:: string '4408371' (length=7)
UPDATE:: Handling the value of
success
within a Conditional Block.
<?php
$data = json_decode($strJson);
$success = $data->response->success;
$groups = $data->response->groups;
if($success){
echo "success";
// EXECUTE SOME CODE FOR A SUCCESS SCENARIO...
}else{
echo "failure";
// EXECUTE SOME CODE FOR A FAILURE SCENARIO...
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With