Processing JSON data
JavaScript Object Notation (JSON) provides web developers with a clean and efficient way to encode data. JSON is a widely adopted format. It simplifies data processing and manipulation. To read more about why you should use JSON, visit http://www.revillweb.com/why-use-json/.
Getting ready
Ensure that your web server is running and you have access to the web root where you can save/upload the files that you will create as part of this recipe.
How to do it…
Learn how to use JSON-formatted data with JavaScript by performing the following steps:
Create a PHP file named
request-3.php
and save it to the web root of your web server. Use the following PHP code to create and output a list of names as JSON data:<?php //Create an array of people $people = array( 1 => array( "firstname" => "Luke", "lastname" => "Skywalker" ), 2 => array( "firstname" => "Darth", "lastname" => "Vader" ), 3 => array( "firstname...