2012-03-07 13 views

risposta

24

se si vuole codificare o decodificare una matrice da o per JSON è possibile utilizzare queste funzioni

$myJSONString = json_encode($myArray); 
$myArray = json_decode($myString); 

json_encode si tradurrà in una stringa JSON, costruito da un array (multidimensionale). json_decode si tradurrà in un Array, costruita da una stringa JSON ben formato

con json_decode si può prendere i risultati del API e solo l'uscita ciò che si vuole, ad esempio:

echo $myArray['payload']['ign']; 
+2

Ahh grazie in effetti era 'print $ myArray-> payload [" 0 "] -> ign;' – Itsyuka

4

Supporto nativo JSON è stato included in PHP dal 5.2 sotto forma di metodi e json_encode()json_decode(). Dovresti usare il primo per generare una variabile PHP in JSON.