-3

Using curl I got the response as JSON format. Now I want to get the value of one object in that JSON response.

{
   "session": {
          "application_id": 2,
          "created_at": "2012-04-03T07:34:48Z",
          "device_id": null,
          "id": 743,
          "nonce": 1308205278,
          "token": "0e7bc95d85c0eb2bf052be3d29d3df523081e87f",
          "ts": 1333438438,
          "updated_at": "2012-04-03T07:34:48Z",
          "user_id": null
   }
}  

Now I want to get the value of token from the above JSON using PHP.

Please help me on this. Thanks in advance.

Shihas
  • 814
  • 15
  • 44
  • 1
    `$arr=json_decode(your_json);` `$arr['session']['token'];` ? – Saad Suri Oct 18 '17 at 08:20
  • This question is answered too many times ... – Jigar Shah Oct 18 '17 at 08:21
  • @JigarShah I know its duplicate question. But it was not working always. I have doubt whether the problem was from `CURL`. That's I thought to ask the question here. Now I think the problem was from the URL that Im calling. Thanks anyway. – Shihas Oct 18 '17 at 08:44

1 Answers1

2

The following should get you token:

$jsonArray = json_decode($jsonString,true)
print_r($jsonArray["session"]["token"])

Regards,

Tarun
  • 3,162
  • 3
  • 29
  • 45