Home > Blockchain >  how to get the MessageId value from That json response using php [duplicate]
how to get the MessageId value from That json response using php [duplicate]

Time:10-03

{"ServiceClass":{"MessageId":"1633236883931745","Status":"0","StatusText":"success","ErrorCode":"0","ErrorText":{},"SMSCount":"1","CurrentCredit":"49.24"}}

CodePudding user response:

Just parse it with json_decode()

$json_response = $get->your_json_response;  

$array = json_decode($json_response, true);
echo $array['ServiceClass']['MessageId'];

Or you prefer an object

$object = json_decode($json_response);
echo $object->ServiceClass->MessageId;

CodePudding user response:

use first Json decode

$json_response ='{"ServiceClass":{"MessageId":"1633236883931745","Status":"0","StatusText":"success","ErrorCode":"0","ErrorText":{},"SMSCount":"1","CurrentCredit":"49.24"}}';

$array = json_decode($json_response, true);

function extractProperty($arr, $propName){
    return $arr['ServiceClass'][$propName];
}

echo 'MessageId : '.extractProperty($array, 'MessageId'). "<br>";
echo 'CurrentCredit : '.extractProperty($array, 'CurrentCredit');
  • Related