$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;
header('Content-Type: application/json');
$colors = array("red","blue","green");
echo json_encode($colors);
//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 },
$data = json_decode(file_get_contents('php://input'), true);
print_r($data);
echo $data;
//code igniter
$query="qry";
$query = $this->db->query($query);
$res=$query->result();
return json_encode($res);
$str_json = file_get_contents('php://input');
$json = '[
{
"displayName": "testing",
"preferredUsername": "testing",
}
]';
$jsonArray = json_decode($json);
foreach($jsonArray as $value){
$displayName = $value->Display Name;
$preferredUsername = $value->Preferred User;
}