<?php
// JSON string
$someJSON = '[{"name":"Jonathan Suh","gender":"male"},{"name":"William Philbin","gender":"male"},{"name":"Allison McKinnery","gender":"female"}]';
// Convert JSON string to Object
$someObject = json_decode($someJSON);
echo $someObject[0]->name; // Access Object data
?>
header('Content-Type: application/json');
$colors = array("red","blue","green");
echo json_encode($colors);
$character = json_decode($data);
echo $character->name;
$data = json_decode(file_get_contents('php://input'), true);
print_r($data);
echo $data;
$data = json_decode($json);
<?php
$data = '{
"name": "Aragorn",
"race": "Human"
}';
$character = json_decode($data);
echo $character->name;
//code igniter
$query="qry";
$query = $this->db->query($query);
$res=$query->result();
return json_encode($res);
<?php
$data = /** whatever you're serializing **/;
header('Content-Type: application/json; charset=utf-8');
echo json_encode($data);