Decode JSON data with PHP
Add a comment
August 7th, 2009
JSON, short for JavaScript Object Notation, is a lightweight computer data interchange format. It is a text-based, human-readable format for representing simple data structures and associative arrays (called objects). If you are running your web server with latest PHP package, then it is so easy to decode JSON data with an in-built function of PHP. json_decode() function decodes a json string. It is available in PHP version 5.2 and later.
An Example:
<?php $json = '{"a":1,"b":2,"c":3,"d":4,"e":5}'; var_dump(json_decode($json)); var_dump(json_decode($json, true)); ?>
Output of the above code will look like this:
object(stdClass)#1 (5) {
["a"] => int(1)
["b"] => int(2)
["c"] => int(3)
["d"] => int(4)
["e"] => int(5)
}
array(5) {
["a"] => int(1)
["b"] => int(2)
["c"] => int(3)
["d"] => int(4)
["e"] => int(5)
}
Read more about JSON:
About The Author








