Created
June 4, 2014 10:35
-
-
Save voku/82ec8dbf96df4bc18df0 to your computer and use it in GitHub Desktop.
create and parse JSON-DATA via PHP - DEMO: http://ideone.com/bz6gjc
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// create JSON data format | |
$json_data = array ('id'=>1,'name'=>"rolf",'country'=>'russia',"office"=>array("google","oracle")); | |
echo json_encode($json_data); | |
echo "\n\n"; | |
// parse JSON data into PHP object | |
$json_string='{"id":1,"name":"rolf","country":"russia","office":["google","oracle"]} '; | |
$obj = json_decode($json_string); | |
//print the parsed data | |
echo $obj->name; //displays rolf | |
echo $obj->office[0]; //displays google | |
echo "\n\n"; | |
// parse JSON data into PHP array | |
$json_string='{"id":1,"name":"rolf","country":"russia","office":["google","oracle"]} '; | |
$array = json_decode($json_string, true); | |
//print the parsed data | |
echo $array['name']; //displays rolf | |
echo $array['office'][0]; //displays google |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment