PHP
php access json object
<?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
?>
read-json-data-response-using-php
$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;
php return json data
header('Content-Type: application/json');
$colors = array("red","blue","green");
echo json_encode($colors);
access json object in php
$character = json_decode($data);
echo $character->name;
how to receive json data in php
$data = json_decode(file_get_contents('php://input'), true);
print_r($data);
echo $data;
how to get data from json array in php
$data = json_decode($json);
access json with php
<?php
$data = '{
"name": "Aragorn",
"race": "Human"
}';
$character = json_decode($data);
echo $character->name;
how to make a json request in php
<?php
$jsonurl = "http://api.wipmania.com/json";
$json = file_get_contents($jsonurl);
var_dump(json_decode($json));
?>
return json in php
//code igniter
$query="qry";
$query = $this->db->query($query);
$res=$query->result();
return json_encode($res);
PHP code to read JSON string on server
$str_json = file_get_contents('php://input');
read-json-data-response-using-php
$json = '[
{
"displayName": "testing",
"preferredUsername": "testing",
}
]';
$jsonArray = json_decode($json);
foreach($jsonArray as $value){
$displayName = $value->Display Name;
$preferredUsername = $value->Preferred User;
}
Returning JSON from a PHP Script
<?php
$data = /** whatever you're serializing **/;
header('Content-Type: application/json; charset=utf-8');
echo json_encode($data);