A common use of JSON is to read data from a web server and display it on a web page.
This chapter will teach you how to exchange JSON data between the client and a PHP server.
PHP provides built-in functions to handle JSON.
Objects in PHP can be converted into JSON using the json_encode()
function.
<?php $myObj->name = “John”; $myObj->age = 30; $myObj->city = “New York”; $myJSON = json_encode($myObj); echo $myJSON; ?> |