Structure de fichier json
Publié : jeu. 09/juin/2022 16:35
Bonjour,
est-ce possible de réaliser le type de structure ci-dessous en Json
une liste de tableau (Array) de données je sait le faire pour 1 Tableau
ex :Données : [ Donnée1, Donnée2, Donnée3, ......... ],
[ Donnée1, Donnée2, Donnée3, ......... ],
Comment ajouter ce deuxième tableau
ci joint l'exemple
Merci
est-ce possible de réaliser le type de structure ci-dessous en Json
une liste de tableau (Array) de données je sait le faire pour 1 Tableau
ex :Données : [ Donnée1, Donnée2, Donnée3, ......... ],
[ Donnée1, Donnée2, Donnée3, ......... ],
Comment ajouter ce deuxième tableau
ci joint l'exemple
Merci
Code : Tout sélectionner
{ "Nom de Table": "Classeur",
"Champs" : [
"Id_Row",
"Type de Pièce",
"Numéro de Pièce",
"Date de Création",
"Compte Tiers",
"Crédit",
"Débit"
]
"Lignes" : [
"1",
"Bon de Livraison",
"894.350",
"08/06/2022",
"401049",
"236.22",
"0.00"
],
[
"2",
"Facture",
"22015623",
"01/06/2022",
"401001",
"736.22",
"0.00"
],
}
#JSON_Create = 0
#JSON_Parse = 1
Procedure.s type_string( value ) ;return type as string for JSON values of null, array, or object or it's contents if a number, boolean or string
Select JSONType(value)
Case #PB_JSON_Null: ProcedureReturn "null"
Case #PB_JSON_String: ProcedureReturn GetJSONString(value)
Case #PB_JSON_Number: ProcedureReturn StrD(GetJSONDouble(value)) ;integer, quad, float also
Case #PB_JSON_Boolean: ProcedureReturn Str(GetJSONBoolean(value))
Case #PB_JSON_Array: ProcedureReturn "array"
Case #PB_JSON_Object: ProcedureReturn "object"
EndSelect
EndProcedure
;
If CreateJSON( #JSON_Create )
Table = SetJSONObject( JSONValue( #JSON_Create ) )
NomTable = AddJSONMember( Table, "Nom de Table" )
SetJSONString( NomTable, "Classeur" )
Tablei = SetJSONArray( AddJSONMember( Table, "Champs") )
SetJSONString( AddJSONElement( Tablei ), "Id_Row" )
SetJSONString(AddJSONElement(Tablei), "Type de Pièce" )
SetJSONString(AddJSONElement(Tablei), "Numéro de Pièce" )
SetJSONString(AddJSONElement(Tablei), "Date de Création" )
SetJSONString(AddJSONElement(Tablei), "Compte Tiers" )
SetJSONString(AddJSONElement(Tablei), "Crédit" )
SetJSONString(AddJSONElement(Tablei), "Débit" )
Tabler = SetJSONArray(AddJSONMember( Table, "Ligne"))
SetJSONString(AddJSONElement(Tabler), "1" )
SetJSONString(AddJSONElement(Tabler), "Bon de Livraison" )
SetJSONString(AddJSONElement(Tabler), "894.350" )
SetJSONString(AddJSONElement(Tabler), "08/06/2022" )
SetJSONString(AddJSONElement(Tabler), "401049" )
SetJSONString(AddJSONElement(Tabler), "236.22" )
SetJSONString(AddJSONElement(Tabler), "0.00" )
Tabler = SetJSONArray(AddJSONMember( Table, "Ligne2"))
SetJSONString(AddJSONElement(Tabler), "2" )
SetJSONString(AddJSONElement(Tabler), "Facture" )
SetJSONString(AddJSONElement(Tabler), "22015623" )
SetJSONString(AddJSONElement(Tabler), "01/06/2022" )
SetJSONString(AddJSONElement(Tabler), "401001" )
SetJSONString(AddJSONElement(Tabler), "736.22" )
SetJSONString(AddJSONElement(Tabler), "0.00" )
EndIf
Debug ComposeJSON( #JSON_Create, #PB_JSON_PrettyPrint)
If ExamineJSONMembers( JSONValue( #JSON_Create ) )
While NextJSONMember( JSONValue( #JSON_Create ) )
If JSONMemberKey( JSONValue( #JSON_Create ) ) = "Champs"
Tableau = GetJSONMember( JSONValue( #JSON_Create ), "Champs")
For i = 0 To JSONArraySize(Tableau ) - 1
Debug GetJSONString( GetJSONElement( Tableau, i ) )
Next i
EndIf
Wend
EndIf