Using json_encode(), we can easily convert an associative array into JSON format:
$data = array("name" => "John", "age" => 25, "city" => "New York");
$json_data = json_encode($data);
echo $json_data;
// Outputs: {"name":"John","age":25,"city":"New York"}
We can decode JSON data into a PHP object:
$json = '{"name":"John","age":25,"city":"New York"}';
$obj = json_decode($json);
echo $obj->name; // Outputs: John
sadik | 10-02-2015 |
good |