AYUDA EN LÍNEA
 WINDEVWEBDEV Y WINDEV MOBILE

Ayuda / WLanguage / Administrar bases de datos / HFSQL / Gestión de la arquitectura de 3 niveles / Funciones WLanguage
  • JSON serialization
Serialize (Example)
JSON serialization
The following example uses JSON serialization.
// Structure to transform into JSON
ST_Product is Structure
// <Serialize> allows you to have a different name in JSON
sName is string <Serialize ="ProductName">
nID is int
nQty is int
mValue is currency <Serialize ="Amount">
END
ST_Person is Structure
sLastName is string <Serialize ="LastName">  
sFirstName is string <Serialize ="FirstName">
dDOB is Date
arrProducts is array of ST_Product
END
arrPersons is array of ST_Person
 
// Fill the data
nPersonIndex is int
nProductIndex is int
nPersonIndex = ArrayAdd(arrPersons)
arrPersons[nPersonIndex].sLastName = "Doe"
arrPersons[nPersonIndex].sFirstName = "John"
arrPersons[nPersonIndex].dDOB = "19880516"
 
nProductIndex = ArrayAdd(arrPersons[nPersonIndex].arrProducts)
arrPersons[nPersonIndex].arrProducts[nProductIndex].mValue = 89.9
arrPersons[nPersonIndex].arrProducts[nProductIndex].nID = 12345724
arrPersons[nPersonIndex].arrProducts[nProductIndex].nQty = 5
arrPersons[nPersonIndex].arrProducts[nProductIndex].sName = "Red jacket"
 
// Retrieve the JSON code
bufJson is Buffer
Serialize(arrPersons.bufJson, psdJSON
//[ {
// "LastName":"Doe",
// "FirstName":"John",
// "dDOB":"1988-05-16",
// "arrProducts":[ {
// "ProductName":"Red jacket",
// "nID":12345724,
// "nQty":5,
// "Amount":89.9
// } ]
// } ]
 
// Send the JSON to a site by POST
HTTPCreateForm("JSONForm")
HTTPAddParameter("JSONForm", "JSONPERSON", bufJson)
HTTPSendForm("JSONForm", ...
"http://MySite/MySite_WEB/US/PAGE_Persons.awp", httpPost)
Versión mínima requerida
  • Versión 10
Comentarios
Haga clic en [Agregar] para publicar un comentario

Última modificación: 27/05/2022

Señalar un error o enviar una sugerencia | Ayuda local