Duncan Archer
0
Q:

php response json

<?PHP
$data = /** whatever you're serializing **/;
header('Content-Type: application/json');
echo json_encode($data);
2

  <?php
$myObj->name = "John";
$myObj->age = 30;
$myObj->city = "New 
  York";

$myJSON = json_encode($myObj);

echo $myJSON;
?>
 
1

$array = array();

$array['Name'] = 'Alex';
$array['Age'] = 37;
$array['Admin'] = TRUE;

$array['Contact'] = array
(
  'Site' => "alexwebdevelop.com",
  'Phone' => 123456789,
  'Address' => NULL
);

$array['Tags'] = array('php', 'web', 'dev');

$json = json_encode($array, JSON_PRETTY_PRINT);

echo '<pre>';
echo $json;
echo '</pre>';

0

New to Communities?

Join the community