Home > Mobile >  How to extract id from json response array
How to extract id from json response array

Time:05-08

How to extract id from this response. I tried like this But return blank page. Below is the response what I'm getting.

<?php 
$res = json_decode($sentMessage ,true);
echo $rc = $res[0]['updates']['id'];
?>

Response :

{
    "_": "updates",
    "updates": [{
        "_": "updateMessageID",
        "id": 291,
        "random_id": 8304404519820905816
    }, {
        "_": "updateReadChannelInbox",
        "flags": 0,
        "channel_id": 1763732152,
        "max_id": 291,
        "still_unread_count": 0,
        "pts": 717
    },

CodePudding user response:

$tes is not defined.

<?php 
$res = json_decode($sentMessage ,true);
echo $rc = $res['updates'][0]['id'];
?>

Here you need to go to updates object, then take the first one (0) and look for its id.

  • Related