Answered by : mobile-star
header('Content-type: application/json');
echo json_encode($array);
Source : | Last Update : Fri, 27 Mar 20
Answered by : silly-skunk-oaa8s6s975xp
header('Content-type: application/json');
http_response_code(200);
echo json_encode([ 'message' => 'thanks'
]);
Source : | Last Update : Fri, 06 May 22
Answered by : nuno-silva
<?php
$jsonurl = "https://reqres.in/api/users/2";
$json = file_get_contents($jsonurl);
$jsonDecode = json_decode($json, true);
echo $jsonDecode['data']['email'];
?>
Source : | Last Update : Tue, 03 Nov 20
Answered by : leonard
$json_data = '{ "stat": "ok", "profile": { "providerName": "testing", "identifier": "http://testing.com/58263223", "displayName": "testing", "preferredUsername": "testing", "name": { "formatted": "testing" }, "url": "http://testing.com/testing/", "photo": "https://securecdn.testing.com/uploads/users/5826/3223/avatar32.jpg?1373393837", "providerSpecifier": "testing" } }';
$json = json_decode($json_data);
echo $json->profile->displayName;
echo $json->profile->preferredUsername;
Source : https://stackoverflow.com/questions/17865544/read-json-data-response-using-php | Last Update : Thu, 03 Feb 22
Answered by : code-grepper
header('Content-Type: application/json');
$colors = array("red","blue","green");
echo json_encode($colors);
Source : | Last Update : Wed, 06 Nov 19
Answered by : perfect-pigeon
$data = json_decode(file_get_contents('php://input'), true);
print_r($data);
echo $data;
Source : https://stackoverflow.com/questions/18866571/receive-json-post-with-php | Last Update : Sun, 08 Nov 20
Answered by : david-cortesi
//PHP File
<?php
$data = /** whatever your data are **/;
header('Content-Type: application/json; charset=utf-8');
echo json_encode($data);
//In JS File
//JQUERY AJAX $.ajax({ url: "path/to_php_file.php", dataType: "json", type: "GET", data: {datax : datax },
Source : https://stackoverflow.com/questions/4064444/returning-json-from-a-php-script | Last Update : Wed, 02 Feb 22
Answered by : annoyed-armadillo-ik49ahzrg9e2
//code igniter
$query="qry";
$query = $this->db->query($query);
$res=$query->result();
return json_encode($res);
Source : | Last Update : Thu, 01 Oct 20
Answered by : leonard
$json = '[ { "displayName": "testing", "preferredUsername": "testing", }
]';
$jsonArray = json_decode($json);
foreach($jsonArray as $value){ $displayName = $value->Display Name; $preferredUsername = $value->Preferred User;
}
Source : https://stackoverflow.com/questions/17865544/read-json-data-response-using-php | Last Update : Thu, 03 Feb 22
Answered by : long-locust-6bchlrhsm70y
<?php
$data = /** whatever you're serializing **/;
header('Content-Type: application/json; charset=utf-8');
echo json_encode($data);
Source : https://stackoverflow.com/questions/4064444/returning-json-from-a-php-script | Last Update : Thu, 25 Nov 21