“convertir a JSON PHP” Código de respuesta

PHP Convertir la matriz a objeto JSON

$myArr = array("apple", "banana", "mango", "jackfruit");

$toJSON = json_encode($myArr);

echo $toJSON;
Lazy Loris

Convertir StdClass a JSON en PHP

$stdClass = new stdClass();
$stdClass->name = "avatar";
$stdClass->age = 31;
$json_data = json_encode ((array) $stdClass);
print_r($json_data); //{"name":"avatar","age":31}
Arun Upadhyay

PHP Convertir la cadena a JSON

$data = '{"Coords":[{"Accuracy":"65","Latitude":"53.277720488429026","Longitude":"-9.012038778269686","Timestamp":"Fri Jul 05 2013 11:59:34 GMT+0100 (IST)"},{"Accuracy":"65","Latitude":"53.277720488429026","Longitude":"-9.012038778269686","Timestamp":"Fri Jul 05 2013 11:59:34 GMT+0100 (IST)"},{"Accuracy":"65","Latitude":"53.27770755361785","Longitude":"-9.011979642121824","Timestamp":"Fri Jul 05 2013 12:02:09 GMT+0100 (IST)"},{"Accuracy":"65","Latitude":"53.27769091555766","Longitude":"-9.012051410095722","Timestamp":"Fri Jul 05 2013 12:02:17 GMT+0100 (IST)"},{"Accuracy":"65","Latitude":"53.27769091555766","Longitude":"-9.012051410095722","Timestamp":"Fri Jul 05 2013 12:02:17 GMT+0100 (IST)"}]}';

$manage = json_decode($data, true);
patrick204nqh

PHP JSON DATA A LA ARRAY

json_decode('{foo:"bar"}');         // this fails
json_decode('{"foo":"bar"}', true); // returns array("foo" => "bar")
json_decode('{"foo":"bar"}');       // returns an object, not an array.
Borma

JSON a la matriz PHP

<?php
        $json = '[{"name":"xxx","phone":"123","email":"[email protected]"},{"name":"yyy","phone":"456","email":"[email protected]"},{"name":"zzz","phone":"678","email":"[email protected]"}]';
        $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>';
      ?>
Fierce Fly

convertir a 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);
?>
CoderHomie

Respuestas similares a “convertir a JSON PHP”

Preguntas similares a “convertir a JSON PHP”

Más respuestas relacionadas con “convertir a JSON PHP” en PHP

Explore las respuestas de código populares por idioma

Explorar otros lenguajes de código