Page 2 sur 3

Re: Question JSON

Publié : ven. 14/févr./2020 2:08
par Shadow
J'ai avancé un peu, voici ce que j'ai réussi à faire :)

Code : Tout sélectionner

If CreateJSON(0)
  
  Niveau1 = SetJSONObject(JSONValue(0))
  Famille = AddJSONMember(Niveau1, "Famille")
  
    Niveau2 = SetJSONObject(Famille)
    Membres = AddJSONMember(Niveau2, "Membres")
    
      Niveau3 = SetJSONObject(Membres)
      Parents = AddJSONMember(Niveau3, "Parents")
      
        Niveau4 = SetJSONObject(Parents)
        
          Papa = AddJSONMember(Niveau4, "Luck")
          
            Niveau5 = SetJSONObject(Papa)
          
              Age = AddJSONMember(Niveau5, "Âge")
              ValeurAge = SetJSONInteger(Age, 35)
              
              Taille = AddJSONMember(Niveau5, "Taille")
              ValeurTaille = SetJSONInteger(Taille, 175)
              
              Poid = AddJSONMember(Niveau5, "Poig")
              Valeurpoid = SetJSONInteger(Poid, 95)
              
          Maman = AddJSONMember(Niveau4, "Lise")
              
            Niveau5 = SetJSONObject(Maman)
          
              Age = AddJSONMember(Niveau5, "Âge")
              ValeurAge = SetJSONInteger(Age, 32)
              
              Taille = AddJSONMember(Niveau5, "Taille")
              ValeurTaille = SetJSONInteger(Taille, 168)
              
              Poid = AddJSONMember(Niveau5, "Poig")
              ValeurPoid = SetJSONInteger(Poid, 75)
              
      Enfants = AddJSONMember(Niveau3, "Enfants")
      
        Niveau4 = SetJSONObject(Enfants)
        
          Enfant1 = AddJSONMember(Niveau4, "John")
          
            Niveau5 = SetJSONObject(Enfant1)
          
              Age = AddJSONMember(Niveau5, "Âge")
              ValeurAge = SetJSONInteger(Age, 8)
              
              Taille = AddJSONMember(Niveau5, "Taille")
              ValeurTaille = SetJSONInteger(Taille, 121)
              
              Poid = AddJSONMember(Niveau5, "Poig")
              ValeurPoid = SetJSONInteger(Poid, 35)
              
          Enfant2 = AddJSONMember(Niveau4, "Alice")
              
            Niveau5 = SetJSONObject(Enfant2)
          
              Age = AddJSONMember(Niveau5, "Âge")
              ValeurAge = SetJSONInteger(Age, 7)
              
              Taille = AddJSONMember(Niveau5, "Taille")
              ValeurTaille = SetJSONInteger(Taille, 111)
              
              Poid = AddJSONMember(Niveau5, "Poig")
              ValeurPoid = SetJSONInteger(Poid, 25)
              
          Enfant3 = AddJSONMember(Niveau4, "Tom")
          
            Niveau5 = SetJSONObject(Enfant3)
          
              Age = AddJSONMember(Niveau5, "Âge")
              ValeurAge = SetJSONInteger(Age, 9)
              
              Taille = AddJSONMember(Niveau5, "Taille")
              ValeurTaille = SetJSONInteger(Taille, 131)
              
              Poid = AddJSONMember(Niveau5, "Poig")
              ValeurPoid = SetJSONInteger(Poid, 40)
              
          Enfant4 = AddJSONMember(Niveau4, "Jule")
          
            Niveau5 = SetJSONObject(Enfant4)
          
              Age = AddJSONMember(Niveau5, "Âge")
              ValeurAge = SetJSONInteger(Age, 11)
              
              Taille = AddJSONMember(Niveau5, "Taille")
              ValeurTaille = SetJSONInteger(Taille, 141)
              
              Poid = AddJSONMember(Niveau5, "Poig")
              ValeurPoid = SetJSONInteger(Poid, 50)
              
      Debug ComposeJSON(0, #PB_JSON_PrettyPrint)
      
EndIf
Ce qui donne:

Code : Tout sélectionner

{
  "Famille": {
      "Membres": {
          "Enfants": {
              "Alice": {
                  "Âge"   : 7,
                  "Taille": 111,
                  "Poig"  : 25
                },
              "Tom"  : {
                  "Âge"   : 9,
                  "Taille": 131,
                  "Poig"  : 40
                },
              "Jule" : {
                  "Âge"   : 11,
                  "Taille": 141,
                  "Poig"  : 50
                },
              "John" : {
                  "Âge"   : 8,
                  "Taille": 121,
                  "Poig"  : 35
                }
            },
          "Parents": {
              "Lise": {
                  "Âge"   : 32,
                  "Taille": 168,
                  "Poig"  : 75
                },
              "Luck": {
                  "Âge"   : 35,
                  "Taille": 175,
                  "Poig"  : 95
                }
            }
        }
    }
}

Re: Question JSON

Publié : ven. 14/févr./2020 8:31
par Micoute
Bonjour Shadow,

les résultats sont bons, mais je pense que pour qu'ils soient utiles, il t'aurait était utile d'utiliser une structure, avec une liste, une map ou un tableau structuré.

Re: Question JSON

Publié : ven. 14/févr./2020 12:23
par Shadow
Micoute ici le but c'est d'apprendre comment ça fonctionne, donc chaque chose en sont temps :)

Re: Question JSON

Publié : ven. 14/févr./2020 14:29
par Micoute
Je suis d'accord, c'est pourquoi je te donne des recommandations.

Re: Question JSON

Publié : ven. 21/févr./2020 12:27
par Shadow
Voici un Tuto en Image de comment marche un Json, si j'ai bien tous compris évidement :mrgreen:
https://drive.google.com/open?id=1j7QL- ... rJC5x36Ab7

Re: Question JSON

Publié : ven. 21/févr./2020 14:09
par Micoute
C'est tout à fait ça, bravo Shadow.

Re: Question JSON

Publié : mer. 04/mars/2020 17:35
par Shadow
Merci Micoute ;)

Je réfléchie à quelque chose actuellement...
A un système style chemin à la windows...

Genre:

Racine\DossierA\DossierB\ >>>

123
"Abc"
[123, 456, 789, "Abc", "Def", 963, "Ghi", 852]
*DossierC

En gros tu entre un chemin avec des \
puis tu as tous ce que ce chemin contient, valeur, chaîne, Tableau, arborescence...

Je sais pas du tout si je suis bien clair là :?
Faut que je vois comment mettre ça en place et si c'est utile parce que le Json c'est bien mais bon pas simple (pas si compliqué).
Simplifier tous ça au maxi quoi...

Vous en pensez quoi vous ?

Re: Question JSON

Publié : mer. 04/mars/2020 19:41
par SPH
Shadow a écrit :Faut que je vois comment mettre ça en place et si c'est utile parce que le Json c'est bien mais bon pas simple (pas si compliqué).
Simplifier tous ça au maxi quoi...

Vous en pensez quoi vous ?
Bin, tu te contredits sans cesse : c'est simple ou c'est pas simple ??

Re: Question JSON

Publié : mer. 04/mars/2020 20:03
par falsam
Utilise une structure récursive que tu peux sauvegarder au format JSON pour l'importer par la suite.

:arrow: https://www.purebasic.fr/french/viewtop ... 81#p204781

Re: Question JSON

Publié : jeu. 05/mars/2020 12:50
par Shadow
Merci falsam ;)

Re: Question JSON

Publié : ven. 06/mars/2020 15:58
par Shadow
Salut,

Je patauge, cogite, cherche...
Je ne sais pas trop si c'est utile et ou je vais mais je trouve ça plus simple....
Comment faire ça svp ?:

Code : Tout sélectionner

MyJson.SimplyJson

Debug MyJson.SimplyJson\Get\ID
Debug MyJson.SimplyJson\Get\MemoryAdress
Debug MyJson.SimplyJson\Get\Value
Debug MyJson.SimplyJson\Get\Value\MemoryAdress
Debug MyJson.SimplyJson\Get\Value\Data
Debug MyJson.SimplyJson\Get\Value\Data\Object
Debug MyJson.SimplyJson\Get\Value\Data\Object\MemoryAdress
Debug MyJson.SimplyJson\Get\Value\Data\Object\Data
Debug MyJson.SimplyJson\Get\Value\Data\Object\Data\Member
Debug MyJson.SimplyJson\Get\Value\Data\Object\Data\Member\MemoryAdress
Debug MyJson.SimplyJson\Get\Value\Data\Object\Data\Member\Name
Debug MyJson.SimplyJson\Get\Value\Data\Object\Data\Member\Value
Debug MyJson.SimplyJson\Get\Value\Data\Object\Data\Member\Value\MemoryAdress

Debug MyJson.SimplyJson\Set\ID
Debug MyJson.SimplyJson\Set\MemoryAdress
Debug MyJson.SimplyJson\Set\Value
Debug MyJson.SimplyJson\Set\Value\MemoryAdress
Debug MyJson.SimplyJson\Set\Value\Data
Debug MyJson.SimplyJson\Set\Value\Data\Object
Debug MyJson.SimplyJson\Set\Value\Data\Object\MemoryAdress
Debug MyJson.SimplyJson\Set\Value\Data\Object\Data
Debug MyJson.SimplyJson\Set\Value\Data\Object\Data\Member
Debug MyJson.SimplyJson\Set\Value\Data\Object\Data\Member\MemoryAdress
Debug MyJson.SimplyJson\Set\Value\Data\Object\Data\Member\Name
Debug MyJson.SimplyJson\Set\Value\Data\Object\Data\Member\Value
Debug MyJson.SimplyJson\Set\Value\Data\Object\Data\Member\Value\MemoryAdress
J'ai bien tenté de faire ça mais bon pas très proban :| :

Code : Tout sélectionner

Structure Member
  
  MemoryAdress.i
  Name.s
  Value.
  
EndStructure

Structure Data
  
  MemoryAdress.i
  Object.Member
  
EndStructure

Structure Value
  
  MemoryAdress.i
  Data.Data
  
EndStructure

Structure Get
  
  ID.i
  MemoryAdress.i
  Value.Value
  
EndStructure

Structure SimplyJson
  
  Get.Get
  Set.Set
  
EndStructure
Bref, ça fume la haut lol :lol:

Re: Question JSON

Publié : dim. 08/mars/2020 0:50
par Shadow
Salut, je continue dans mes recherches, le but étang de faire un système qui utiliserais les Json
mais sous forme de Patch, beaucoup plus simple pour s'y retrouver je trouve dans les données.

Bon alors j'ai pondus ça, je continue les recherche:

Code : Tout sélectionner

; Imaginez un genre d'explorateur à la windows ou les adresses sont des Patchs vers les données que l'on souhaite.

Structure PatchData
  
  Key.s
  Value.s
  
EndStructure

Structure Patch
  
  Array Block.PatchData(9999) ; Emplacement au coeur du dossier (Patch).
  
EndStructure

Global NewMap Explorer.Patch() ; Map qui sert pour le Patch (Adresse) des données.


Explorer.Patch("Vehicules\Aérien")\Block(0)\Key = "Montgolfière"
Explorer.Patch("Vehicules\Aérien")\Block(0)\Value = "123"

Explorer.Patch("Vehicules\Aérien")\Block(1)\Key = "Dirigeable"
Explorer.Patch("Vehicules\Aérien")\Block(1)\Value = "124"

Explorer.Patch("Vehicules\Aérien")\Block(2)\Key = "DeltaPlane"
Explorer.Patch("Vehicules\Aérien")\Block(2)\Value = "125"

Explorer.Patch("Vehicules\Aérien")\Block(3)\Key = "Avion"
Explorer.Patch("Vehicules\Aérien")\Block(3)\Value = "126"

Explorer.Patch("Vehicules\Aérien")\Block(4)\Key = "Hélicopter"
Explorer.Patch("Vehicules\Aérien")\Block(4)\Value = "127"


Explorer.Patch("Vehicules\Terrestre")\Block(0)\Key = "Voiture"
Explorer.Patch("Vehicules\Terrestre")\Block(0)\Value = "128"

Explorer.Patch("Vehicules\Terrestre")\Block(1)\Key = "Moto"
Explorer.Patch("Vehicules\Terrestre")\Block(1)\Value = "129"

Explorer.Patch("Vehicules\Terrestre")\Block(2)\Key = "Vélo"
Explorer.Patch("Vehicules\Terrestre")\Block(2)\Value = "130"


Explorer.Patch("Vehicules\Maritime")\Block(0)\Key = "Zodiaque"
Explorer.Patch("Vehicules\Maritime")\Block(0)\Value = "128"

Explorer.Patch("Vehicules\Maritime")\Block(1)\Key = "Bateau"
Explorer.Patch("Vehicules\Maritime")\Block(1)\Value = "129"

Explorer.Patch("Vehicules\Maritime")\Block(2)\Key = "Péniche"
Explorer.Patch("Vehicules\Maritime")\Block(2)\Value = "130"


; Le père a un Nom, il s'appel Tome, il à 38 ans.
Explorer.Patch("Père\Nom\Tome")\Block(0)\Key = "Age"
Explorer.Patch("Père\Nom\Tome")\Block(0)\Value = "38"

; Tome a une compagne qui se nomme Marine, qui elle a un enfants qui s'appel Julien, qui lui à une compagne nommé Julie qui a 21 ans.
Explorer.Patch("Père\Compagne\Marine\Enfants\Julien\Compagne\Julie")\Block(0)\Key = "Age"
Explorer.Patch("Père\Compagne\Marine\Enfants\Julien\Compagne\Julie")\Block(0)\Value = "21"


Explorer.Patch("MyJson")\Block(0)\Key = "ID"
Explorer.Patch("MyJson")\Block(0)\Value = "1"

Explorer.Patch("MyJson")\Block(1)\Key = "MemoryAdress"
Explorer.Patch("MyJson")\Block(1)\Value = "123456"

Explorer.Patch("MyJson\Data")\Block(0)\Key = "MemoryAdress"
Explorer.Patch("MyJson\Data")\Block(0)\Value = "234567"

Explorer.Patch("MyJson\Data\Object")\Block(0)\Key = "MemoryAdress"
Explorer.Patch("MyJson\Data\Object")\Block(0)\Value = "123568"

Explorer.Patch("MyJson\Data\Object\Member")\Block(0)\Key = "MemoryAdress"
Explorer.Patch("MyJson\Data\Object\Member")\Block(0)\Value = "241352"

Explorer.Patch("MyJson\Data\Object\Member")\Block(1)\Key = "Name"
Explorer.Patch("MyJson\Data\Object\Member")\Block(1)\Value = "Member 1"

Explorer.Patch("MyJson\Data\Object\Member\Value")\Block(0)\Key = "MemoryAdress"
Explorer.Patch("MyJson\Data\Object\Member\Value")\Block(0)\Value = "315246"

Explorer.Patch("MyJson\Data\Object\Member\Value")\Block(1)\Key = "Data"
Explorer.Patch("MyJson\Data\Object\Member\Value")\Block(1)\Value = "123 Abc"

ForEach Explorer.Patch()
  
  For Index = 0 To ArraySize(Explorer.Patch(MapKey(Explorer.Patch()))\Block())
    If Explorer.Patch(MapKey(Explorer.Patch()))\Block(Index)\Key > ""
      Debug "Patch: " + Chr(34) + MapKey(Explorer.Patch()) + Chr(34) + ", Key: " + Chr(34) + Explorer.Patch(MapKey(Explorer.Patch()))\Block(Index)\Key + Chr(34) + ", Value = " + Chr(34) + Explorer.Patch(MapKey(Explorer.Patch()))\Block(Index)\Value + Chr(34)
    EndIf
  Next
  
Next

Re: Question JSON

Publié : dim. 08/mars/2020 9:26
par Naheulf
Heuu.... Alors là tu m'as perdu ! J'attends de voir un exemple plus concret par-ce que là, pour moi, c'est un peu le flou artistique :lol:

Re: Question JSON

Publié : dim. 08/mars/2020 13:10
par Shadow
Naheulf a écrit :Heuu.... Alors là tu m'as perdu ! J'attends de voir un exemple plus concret par-ce que là, pour moi, c'est un peu le flou artistique :lol:
Ouais je sais je patauge un peu, mais c'est pas plus mal lol.

Re: Question JSON

Publié : dim. 08/mars/2020 13:52
par Shadow
Encore plus simple ainsi:

Code : Tout sélectionner

Structure PatchData
  Value.s
EndStructure

Structure Patch
  Map Member.PatchData() ; Emplacement avec une clef au coeur du dossier (Patch).
EndStructure

Global NewMap SimplyJson.Patch() ; Map qui sert pour le Patch (Adresse) des données.


SimplyJson.Patch("Vehicules\Aérien")\Member("Montgolfière")\Value = "123"
SimplyJson.Patch("Vehicules\Aérien")\Member("Dirigeable")\Value = "124"
SimplyJson.Patch("Vehicules\Aérien")\Member("DeltaPlane")\Value = "125"
SimplyJson.Patch("Vehicules\Aérien")\Member("Avion")\Value = "126"
SimplyJson.Patch("Vehicules\Aérien")\Member("Hélicopter")\Value = "127"

SimplyJson.Patch("Vehicules\Terrestre")\Member("Voiture")\Value = "128"
SimplyJson.Patch("Vehicules\Terrestre")\Member("Moto")\Value = "129"
SimplyJson.Patch("Vehicules\Terrestre")\Member("Vélo")\Value = "130"

SimplyJson.Patch("Vehicules\Maritime")\Member("Zodiaque")\Value = "128"
SimplyJson.Patch("Vehicules\Maritime")\Member("Bateau")\Value = "129"
SimplyJson.Patch("Vehicules\Maritime")\Member("Péniche")\Value = "130"


; Le père a un Nom, il s'appel Tome, il à 38 ans.
SimplyJson.Patch("Père\Nom\Tome")\Member("Age")\Value = "38"

; Tome a une compagne qui se nomme Marine, qui elle a un enfants qui s'appel Julien, qui lui à une compagne nommé Julie qui a 21 ans.
SimplyJson.Patch("Père\Compagne\Marine\Enfants\Julien\Compagne\Julie")\Member("Age")\Value = "21"


SimplyJson.Patch("MyJson")\Member("ID")\Value = "1"
SimplyJson.Patch("MyJson")\Member("MemoryAdress")\Value = "123456"
SimplyJson.Patch("MyJson\Data")\Member("MemoryAdress")\Value = "234567"
SimplyJson.Patch("MyJson\Data\Object")\Member("MemoryAdress")\Value = "123568"
SimplyJson.Patch("MyJson\Data\Object\Member")\Member("MemoryAdress")\Value = "241352"
SimplyJson.Patch("MyJson\Data\Object\Member")\Member("Name")\Value = "Member 1"
SimplyJson.Patch("MyJson\Data\Object\Member\Value")\Member("MemoryAdress")\Value = "315246"
SimplyJson.Patch("MyJson\Data\Object\Member\Value")\Member("Data")\Value = "123 Abc"

ForEach SimplyJson.Patch()
  
  ForEach SimplyJson.Patch(MapKey(SimplyJson.Patch()))\Member()
    Debug "Patch: " + Chr(34) + MapKey(SimplyJson.Patch()) + Chr(34) + ", Member Name: " + Chr(34) + MapKey(SimplyJson.Patch(MapKey(SimplyJson.Patch()))\Member()) + Chr(34) + ", Value = " + Chr(34) + SimplyJson.Patch(MapKey(SimplyJson.Patch()))\Member()\Value + Chr(34)
  Next
  
Next

Le Json c'est la mouise à utiliser, ya des tonnes d'adresses mémoire à gérer, c'est vraiment le bordel !
Alors je cherche à faire plus simple, rendre l'utilisation d'un Json plus simplement comme ici (pas fini)
Tu vois, sous forme de Path (Adresse), c'est beaucoup plus simple à appréhender et comprendre.