Search
 
SCRIPT & CODE EXAMPLE
 

PHP

get json kay value php

$arr = json_decode($json, true);
 
// Loop through the associative array
foreach($arr as $key=>$value){
    echo $key . " => " . $value . "<br>";
}
Comment

php return json

header('Content-type: application/json');
echo json_encode($array);
Comment

php return json data

header('Content-Type: application/json'); 

$colors = array("red","blue","green");
echo json_encode($colors);
Comment

php return a json response

//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 },
Comment

access json object in php

$character = json_decode($data);
echo $character->name;
Comment

convert to json php

<?php
	// the php array
  	$array = array();
	$array['key1'] = "value1";
	$array['key2'] = "value2";
	$array['key3'] = "value3";

	// encode the php array into JSON format
	$json = json_encode($array);

	// check out the results
	var_dump($json);
?>
Comment

how to receive json data in php

$data = json_decode(file_get_contents('php://input'), true);
print_r($data);
echo $data;
Comment

json to php array

<?php
        $json = '[{"name":"xxx","phone":"123","email":"a@a.com"},{"name":"yyy","phone":"456","email":"b@a.com"},{"name":"zzz","phone":"678","email":"c@a.com"}]';
        $json_decoded = json_decode($json);
        echo '<table>';
        foreach($json_decoded as $result){
          echo '<tr>';
            echo '<td>'.$result->name.'</td>';
            echo '<td>'.$result->phone.'</td>';
            echo '<td>'.$result->email.'</td>';
          echo '</tr>';
        }
        echo '</table>';
      ?>
Comment

is json php

function isJson($str) {
   json_decode($str);
   return json_last_error() === JSON_ERROR_NONE;
}
Comment

is json php

function isJson($str) {
   json_decode($str);
   return json_last_error() === JSON_ERROR_NONE;
}
Comment

how to get data from json array in php

 $data = json_decode($json);
Comment

json php

<?php
header("Content-Type: application/json; charset=utf-8");
if (!empty($_REQUEST['q'])){
    $q = $_REQUEST['q'];
    require_once('api-key.php');
    $apiUrl = "http://api.openweathermap.org/data/2.5/weather?q=" . $q . "&lang=fr&units=metric&APPID=" . API_KEY;
  
    $response = file_get_contents($apiUrl, False);
    $data = json_decode($response, true); // $data = TABLEAU PHP
  
    setLocale(LC_TIME,"fr_FR.UTF-8");
    date_default_timezone_set("Europe/Paris");
    $today = strftime('%A %d %B %y',time());
    $hour = date('H:i:s');
    // on prépare un tableau $json pour la réponse
    $json =  array("lieu" => $q,
                   "jour" => $today, 
                   "heure"=> $hour,
                   "meteo"=> array());
    $json['meteo']['main'] = $data['main'];
    $json['meteo']['description'] = $data['weather'][0]['description'];
    $json['meteo']['id'] = $data['weather'][0]['id'];
    echo json_encode($json,JSON_PRETTY_PRINT);
   }
Comment

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));
?>
Comment

access json with php

<?php

$data = '{
	"name": "Aragorn",
	"race": "Human"
}';

$character = json_decode($data);
echo $character->name;
Comment

return json in php

//code igniter
$query="qry";
$query = $this->db->query($query);
$res=$query->result();
return json_encode($res);
Comment

how to extract data from json in php

$json = '
{
    "type": "donut",
    "name": "Cake",
    "toppings": [
        { "id": "5002", "type": "Glazed" },
        { "id": "5006", "type": "Chocolate with Sprinkles" },
        { "id": "5004", "type": "Maple" }
    ]
}';

$yummy = json_decode($json);

print_r($yummy);
Comment

php object to json

function getJsonData(){
    $var = get_object_vars($this);
    foreach ($var as &$value) {
        if (is_object($value) && method_exists($value,'getJsonData')) {
            $value = $value->getJsonData();
        }
    }
    return $var;
}
Comment

json en php

{"data":[
 { "sub_data1":"value1", "sub_data2":"value2","sub_data_n":"value n" },
 { "sub_data2":"value2","sub_data2":"value2", "sub_data_n":"value n" },
 { "sub_data n":"value n ", "sub_data2":"value2","sub_data_n":"value n" }
]}
Comment

Returning JSON from a PHP Script

<?php
$data = /** whatever you're serializing **/;
header('Content-Type: application/json; charset=utf-8');
echo json_encode($data);
Comment

PREVIOUS NEXT
Code Example
Php :: how to find datatype of a variable in php 
Php :: php loop through every day of the year 
Php :: laravel run php server by ipv4 
Php :: create laravel project with composer 
Php :: php get previous url 
Php :: create laravel project specific version 
Php :: In PackageManifest.php line 131: Undefined index: name laravel 7 
Php :: php replace space with 20 
Php :: php time format am pm 
Php :: carbon start of day 
Php :: php xml to array 
Php :: laravel uppercase first letter 
Php :: link acf 
Php :: find word in text in laravel 
Php :: laravel run migration 
Php :: migrate specific migration laravel 
Php :: Disable update notification for individual plugins 
Php :: php remove last element array 
Php :: php version change ubuntu 
Php :: add tags to custom post type 
Php :: datetime difference in php 
Php :: php curl delete request 
Php :: get year in laravel 8 
Php :: install phpmyadmin ubuntu 
Php :: must be an instance of IlluminateHttpRequest 
Php :: ian holm 
Php :: cast array to object php 
Php :: How to Get the last element of an array in PHP – end() 
Php :: install php7.4 linux 
Php :: phpMyAdmin is not able to cache templates 
ADD CONTENT
Topic
Content
Source link
Name
5+7 =