Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JSON encode and decode on PHP

Tags:

json

php

I have JSON output encoded.

$responseJSON
{"status":1,"content":{"sessionid":"4c86cf1acac07811db6ec670e0b9cdd2"}}

now I do a decode on that

$decoded=json_decode($responseJSON);

print_r($decoded)

I get

stdClass Object (
  [status] => 1 
  [content] => stdClass Object ( 
    [sessionid] => 4c86cf1acac07811db6ec670e0b9cdd2 
  ) 
) 

I don't want decoded like that.

how do I decode to an normal array without those stdClass tag?

like image 850
lilzz Avatar asked Nov 28 '22 17:11

lilzz


1 Answers

Don't have enough rep to comment on other peoples comments

To get the info out after you've processed it with

$decoded = json_decode( $responseJSON, TRUE );

You can access all the information inside of it as normal. do a

var_dump($decoded);

just incase it add's levels you wouldn't expect Then just proceed as usual

echo $decoded['status']
echo $decoded['content']['sessionid']
like image 163
Bankzilla Avatar answered Dec 05 '22 16:12

Bankzilla