Search notes:

PHP: json_decode

<?php

$jsonText = ' {
     "num" : 42,
     "txt" : "Hello world",
     "obj" : {
        "val1": "foo",
        "val2": "bar",
        "val3": "baz"
     },
     "ary": ["one", "two", "three"]
  }
';


$jsonObj = json_decode($jsonText, true);

print_r(var_dump($jsonObj));

print($jsonObj['num']         . "\n");
print($jsonObj['txt']         . "\n");
print($jsonObj['obj']['val2'] . "\n");
print($jsonObj['ary'][1]      . "\n");

?>
Github repository about-php, path: /json/decode.php

See also

JSON

Index

Fatal error: Uncaught PDOException: SQLSTATE[HY000]: General error: 8 attempt to write a readonly database in /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php:78 Stack trace: #0 /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php(78): PDOStatement->execute(Array) #1 /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php(30): insert_webrequest_('/notes/developm...', 1741107279, '3.22.66.210', 'Mozilla/5.0 App...', NULL) #2 /home/httpd/vhosts/renenyffenegger.ch/httpsdocs/notes/development/web/php/snippets/json/decode(62): insert_webrequest() #3 {main} thrown in /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php on line 78