I am trying to integrate SMS balance to my website through API. API provides JSON for that . I am trying to extract an element from JSON data. I have tried a few ways but no success . I had tried to convert the JSON data to PHP readable like this $data = json_decode($json);. but i am not able to extract a element I am getting error 'Trying to access array offset on value of type null' please help here is my JSON output .And i want to SMS data from that JSON through PHP Thank You
{
"balance":{
"sms":1852
},
"status":"success"
}
here is my code this json data is store in response in below code :-
$apiKey = urlencode('***************');
// Prepare data for POST request
$data = array('apikey' => $apiKey);
// Send the POST request with cURL
$ch = curl_init('https://api.textlocal.in/balance/');
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
curl_close($ch);
// Process your response here
echo $response;
$object = json_decode($response);
echo $object[0];