Création de fichier json avec PHP
J'essaye de créer un fichier json. Mais je n'arrive pas à le créer correctement pour l'analyser avec javascript. Est-ce que quelqu'un pourrait me dire si mon json est correct ? et si il ne l'ait pas, comment crée un simple tableau assosiatif dans un fichier Json.
PHP :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13
|
$jsonFormat = array(
"fonctions"=>array(
1=>"calculPrix()",
2=>"calculPrix1()",
3=>"calculPrix2()",
)
);
$jsonFormat = json_encode($jsonFormat);
echo $jsonFormat;
// Renvoi : {"fonctions":{"1":"calculPrix()","2":"calculPrix1()","3":"calculPrix2()"}} |
Code:
1 2 3 4 5 6 7 8
|
$jsonFormat = array();
$jsonFormat['fonctions'][] = 'calculPrix()';
$jsonFormat['fonctions'][] = 'calculPrix1()';
$jsonFormat['fonctions'][] = 'calculPrix2()';
// Renvoi : {"fonctions":["calculPrix()","calculPrix1()","calculPrix2()"]} |
D'avance merci pour les personnes qui se penchent sur ma question ;)