1<?php
2 // JSON string
3 $someJSON = '[{"name":"Jonathan Suh","gender":"male"},{"name":"William Philbin","gender":"male"},{"name":"Allison McKinnery","gender":"female"}]';
4
5 // Convert JSON string to Array
6 $someArray = json_decode($someJSON, true);
7 print_r($someArray); // Dump all data of the Array
8 echo $someArray[0]["name"]; // Access Array data
9
10 // Convert JSON string to Object
11 $someObject = json_decode($someJSON);
12 print_r($someObject); // Dump all data of the Object
13 echo $someObject[0]->name; // Access Object data
14?>
15
1$personJSON = '{"name":"Johny Carson","title":"CTO"}';
2
3$person = json_decode($personJSON);
4
5echo $person->name; // Johny Carson
1header('Content-Type: application/json');
2
3$colors = array("red","blue","green");
4echo json_encode($colors);
1$data = json_decode(file_get_contents('php://input'), true);
2print_r($data);
3echo $data;
4