IdentifiantMot de passe
Loading...
Mot de passe oubli� ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les r�ponses en temps r�el, voter pour les messages, poser vos propres questions et recevoir la newsletter

JavaScript Discussion :

Array to String en JSON


Sujet :

JavaScript

Vue hybride

Message pr�c�dent Message pr�c�dent   Message suivant Message suivant
  1. #1
    Membre � l'essai
    Homme Profil pro
    �tudiant
    Inscrit en
    Mai 2016
    Messages
    5
    D�tails du profil
    Informations personnelles :
    Sexe : Homme
    �ge : 29
    Localisation : Belgique

    Informations professionnelles :
    Activit� : �tudiant

    Informations forums :
    Inscription : Mai 2016
    Messages : 5
    Par d�faut Array to String en JSON
    Bonjour,

    J'ai une erreur de conversion JSON a cause de la ligne de code 62. Mais je ne vois o� est mon erreur. Peut-�tre que quelqu'un le verra. Nom : Capture.PNG
Affichages : 167
Taille : 180,1 Ko
    Code : S�lectionner tout - Visualiser dans une fen�tre � part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    <?php
    /**
     * Created by PhpStorm.
     * User: Killian Kaeses
     * Date: 02/05/2016
     * Time: 16:48
     */
    class Config{
        public $name;
        public $defaultName = "inc/config.ini.php";
        public $data;
        public $writer = "inc/useConfig.php";
        function __construct($nom = ""){
            if($nom == "")$this->name = $this->defaultName;
            $this->load();
        }
        function load(){
            $this->data=parse_ini_file($this->name, true);
        }
        public function getData($g, $n){
            if(isset($this->data[$g][$n])) return $this->data[$g][$n];
            else return "[$g][$n] inconnu";
        }
        public function getForm(){
            if(!isset($this->data)) return('config not loaded');
            $data = $this->data;
            $out[] = "<form id='conf' name='conf' method=\"post\" action=\"$this->writer\">";
            foreach($data as $group=>$property){
                if($group!="erreur")$out[]=$this->handleGroup($group, $property);
            }
            $out[]= "<input id='send' name='send' type=\"submit\" value=\"Envoyer\">";
            $out[]= "</form>";
            return implode("\n", $out);
        }
        function handleGroup($g, $p){
            $tmp = "<fieldset>
                      <legend>" . $g . "</legend>";
            if(isset($p["comment"])) $tmp .= "<p id=comment>".$p["comment"]."</p>";
            foreach($p as $k => $v){
                if($k!="comment"&&$k!="type"&&$k!="choix"&&$k!="min"&&$k!="max"){
                    if(is_numeric($v)) {
                        $tmp .= "<p><label for='" . $g."[".$k . "]' style='text-transform : capitalize;'>"
                            . $k . " : </label><input type=number value='"
                            . $v . "' step='1' id='" . $g."[".$k . "]' name='"
                            . $g."[".$k . "]'";
                        if (isset($p["min"])) {
                            $tmp .= " min='" . $p["min"] . "'";
                        }
                        if (isset($p["max"])) {
                            $tmp .= " max='" . $p["max"] . "'";
                        }
                        $tmp .= ">";
                        if(isset($p["min"])&&isset($p["max"])){
                            if($p["min"]==$p["max"]){
                                $tmp .= " (non modifiable) <script>document.getElementById(\"".$g."[".$k."]\").disabled = true;</script>";
                            }else{
                                $tmp .= " min($p[min]) max ($p[min]) step(1)";
                            }
                        }
                        $tmp .= "</p>";
                    }else{
                        $tmp .= "<p><label for='" . $g."[".$k . "]'>" . $k . " : </label><input type=text value='" .$v . "' id='" . $g."[".$k . "]' name='" . $g."[".$k . "]'></p>";
                    }
                }
            }
            if (isset($p["type"])&&isset($p["choix"])) {
                $tmp .= "<p style='text-transform : capitalize;'>type : ";
                foreach ($p["type"] as $v) {
                    $tmp .= "<input type='checkbox' name='" . $g."[".$v . "]' id='" . $g."[".$v . "]' style='margin-left : 10px;'><label for='" . $v . "'>" . $v . "</label>";
                }
                $tmp .= "</p>";
                foreach ($p["choix"] as $v) {
                    $tmp .= "<script> document.getElementById('" . $g."[".$v . "]').checked = true; </script>";
                }
            }
            $tmp .= "</fieldset>";
            return $tmp;
        }
        public function writeConfig(){
            unlink($this->name);
            $monfichier = fopen($this->name, 'a+');
            fputs($monfichier, "[erreur]\n");
            fputs($monfichier, "interdit = \"<?php echo 'Vous n\\'êtes pas autorisé à voir ce contenu.\"'; exit; ?>\"\n");
            fputs($monfichier, "comment = \"; Les commentaires commencent par ';', comme dans php.ini\"\n\n");
            foreach($this->data as $k => $v){
                $isArrayDone = 0;
                if($k != "erreur") {
                    fputs($monfichier, "[" . $k . "]\n");
                    foreach ($v as $k2 => $v2) {
                        if(is_array($v2)){
                            if($isArrayDone==0) {
                                foreach ($v2 as $i) {
                                    if (is_numeric($i)) {
                                        fputs($monfichier, $k2 . "[] = $i\n");
                                    } else {
                                        fputs($monfichier, $k2 . "[] = \"$i\"\n");
                                    }
                                }
                                foreach ($v2 as $i) {
                                    if (isset($_POST[$k][$i])) {
                                        if (is_numeric($i)) {
                                            fputs($monfichier, "choix[] = $i\n");
                                        } else {
                                            fputs($monfichier, "choix[] = \"$i\"\n");
                                        }
                                    }
                                }
                                $isArrayDone = 1;
                            }
                        }else if(isset($_POST[$k][$k2])){
                            if(is_numeric($_POST[$k][$k2])){
                                fputs($monfichier, $k2 . " = " . $_POST[$k][$k2]."\n");
                            }else{
                                fputs($monfichier, $k2 . " = \"" . $_POST[$k][$k2]."\"\n");
                            }
                        }else{
                            if(is_numeric($v2)){
                                fputs($monfichier, $k2 . " = ".$v2."\n");
                            }else{
                                fputs($monfichier, $k2 . " = \"".$v2."\"\n");
                            }
                        }
                    }
                    fputs($monfichier, "\n");
                }
            }
            fclose($monfichier);
            return "Configuration sauvegardée";
        }
    }
    Merci d'avance

  2. #2
    R�dacteur/Mod�rateur

    Avatar de SpaceFrog
    Homme Profil pro
    D�veloppeur Web Php Mysql Html Javascript CSS Apache - Int�grateur - Bidouilleur SharePoint
    Inscrit en
    Mars 2002
    Messages
    39 659
    D�tails du profil
    Informations personnelles :
    Sexe : Homme
    �ge : 75
    Localisation : Royaume-Uni

    Informations professionnelles :
    Activit� : D�veloppeur Web Php Mysql Html Javascript CSS Apache - Int�grateur - Bidouilleur SharePoint
    Secteur : Industrie

    Informations forums :
    Inscription : Mars 2002
    Messages : 39 659
    Billets dans le blog
    1
    Par d�faut
    ben faudrait voir la t�te du string json ...
    Ma page Developpez - Mon Blog Developpez
    Pr�sident du CCMPTP (Comit� Contre le Mot "Probl�me" dans les Titres de Posts)
    Deux r�gles du succ�s: 1) Ne communiquez jamais � quelqu'un tout votre savoir...
    Votre post est r�solu ? Alors n'oubliez pas le Tag

    Venez sur le Chat de D�veloppez !

  3. #3
    Membre � l'essai
    Homme Profil pro
    �tudiant
    Inscrit en
    Mai 2016
    Messages
    5
    D�tails du profil
    Informations personnelles :
    Sexe : Homme
    �ge : 29
    Localisation : Belgique

    Informations professionnelles :
    Activit� : �tudiant

    Informations forums :
    Inscription : Mai 2016
    Messages : 5
    Par d�faut
    Mais je veux bien, mais je n'en n'ai pas. Il ne me retourne rien.

  4. #4
    Mod�rateur

    Avatar de NoSmoking
    Homme Profil pro
    Inscrit en
    Janvier 2011
    Messages
    17 211
    D�tails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Is�re (Rh�ne Alpes)

    Informations forums :
    Inscription : Janvier 2011
    Messages : 17 211
    Par d�faut
    Bonjour,
    Il ne me retourne rien.
    ben si puisse que l'on le devine dans l'image de ta console !

  5. #5
    Membre � l'essai
    Homme Profil pro
    �tudiant
    Inscrit en
    Mai 2016
    Messages
    5
    D�tails du profil
    Informations personnelles :
    Sexe : Homme
    �ge : 29
    Localisation : Belgique

    Informations professionnelles :
    Activit� : �tudiant

    Informations forums :
    Inscription : Mai 2016
    Messages : 5
    Par d�faut
    Ce que je voulais dire c'est qu'il ne me r�ponds rien dans mon html. Je comprends pas pourquoi il ne me l'affiche pas

  6. #6
    Mod�rateur

    Avatar de NoSmoking
    Homme Profil pro
    Inscrit en
    Janvier 2011
    Messages
    17 211
    D�tails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Is�re (Rh�ne Alpes)

    Informations forums :
    Inscription : Janvier 2011
    Messages : 17 211
    Par d�faut
    Malheureusement on n'a qu'une image et pas de code pour voir si r�ellement tu fait correctement, la seule chose qui appara�t est $('#title').html(e.innerHTML);, autant dire bonjour la n�buleuse ...

Discussions similaires

  1. [JSON] Probl�me de Cast Array en String
    Par helter_skelter dans le forum Format d'�change (XML, JSON...)
    R�ponses: 0
    Dernier message: 21/10/2009, 12h02
  2. Convertir un cell array en string
    Par Sensib dans le forum MATLAB
    R�ponses: 3
    Dernier message: 09/11/2006, 13h12
  3. [D6] Conversion Array of String en String
    Par wizdom dans le forum Delphi
    R�ponses: 2
    Dernier message: 23/05/2006, 17h01
  4. [FreePascal] Array of string
    Par w0lf dans le forum Free Pascal
    R�ponses: 3
    Dernier message: 21/01/2006, 18h46
  5. TStringList en array of string
    Par JediKerian dans le forum Langage
    R�ponses: 2
    Dernier message: 20/03/2003, 15h37

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo