DOCUMENTATION EN LIGNE
DE WINDEVWEBDEV ET WINDEV MOBILE

Aide / WLangage / Gestion des bases de données / HFSQL / Gestion du 3tiers / Fonctions WLangage
  • Sérialisation JSON
Sérialise (Exemple)
Sérialisation JSON
L'exemple suivant utilise la sérialisation JSON.
// Structure à transformer en JSON
ST_Produit est une Structure
// <Sérialise> permet d'avoir un nom différent dans le JSON
sNom est une chaîne <sérialise ="NomProduit">
nID est un entier
nQte est un entier
mValeur est un monétaire <sérialise ="Montant">
FIN
ST_Personne est une Structure
sNom est une chaîne <sérialise ="Nom">  
sPrenom est une chaîne <sérialise ="Prenom">
dDateNaissance est une Date
tabProduits est un tableau de ST_Produit
FIN
tabPersonnes est un tableau de ST_Personne
 
// Remplissage des données
nIndicePersonne est un entier
nIndiceProduit est un entier
nIndicePersonne = TableauAjoute(tabPersonnes)
tabPersonnes[nIndicePersonne].sNom = "Dupond"
tabPersonnes[nIndicePersonne].sPrénom = "Jean"
tabPersonnes[nIndicePersonne].dDateNaissance = "19880516"
 
nIndiceProduit = TableauAjoute(tabPersonnes[nIndicePersonne].tabProduits)
tabPersonnes[nIndicePersonne].tabProduits[nIndiceProduit].mValeur = 89.9
tabPersonnes[nIndicePersonne].tabProduits[nIndiceProduit].nID = 12345724
tabPersonnes[nIndicePersonne].tabProduits[nIndiceProduit].nQte = 5
tabPersonnes[nIndicePersonne].tabProduits[nIndiceProduit].sNom = "Veste rouge"
 
// Récupération du code JSON
bufJson est un Buffer
Sérialise(tabPersonnes, bufJson, psdJSON)
//[ {
// "Nom":"Dupond",
// "Prenom":"Jean",
// "dDateNaissance":"1988-05-16",
// "tabProduits":[ {
// "NomProduit":"Veste rouge",
// "nID":12345724,
// "nQte":5,
// "Montant":89.9
// } ]
// } ]
 
// Envoi du JSON sur un site en POST
HTTPCréeFormulaire("FormJSON")
HTTPAjouteParamètre("FormJSON", "PERSONNEJSON", bufJson)
HTTPEnvoieFormulaire("FormJSON", ...
"http://MonSite/MonSite_WEB/FR/PAGE_Personnes.awp", httpPost)
Version minimum requise
  • Version 10
Documentation également disponible pour…
Commentaires
Cliquez sur [Ajouter] pour publier un commentaire

Dernière modification : 25/05/2022

Signaler une erreur ou faire une suggestion | Aide en ligne locale