PC SOFT

WINDEVWEBDEV AND WINDEV MOBILE
ONLINE HELP

Home | Sign in | English UK
  • JSON serialization
Serialize (Example)
JSON serialization
The following example is using the 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
nPersonSubscript is int
nProductSubscript is int
nPersonSubscript = ArrayAdd(arrPersons)
arrPersons[nPersonSubscript].sLastName = "Doe"
arrPersons[nPersonSubscript].sFirstName = "John"
arrPersons[nPersonSubscript].dDOB = "19880516"
 
nProductSubscript = ArrayAdd(arrPersons[mPersonSubscript].arrProducts)
arrPersons[nPersonSubscript].arrProducts[nProductSubscript].mValue = 89.9
arrPersons[nPersonSubscript].arrProducts[nProductSubscript].nID = 12345724
arrPersons[nPersonSubscript].arrProducts[nProductSubscript].nQty = 5
arrPersons[nPersonSubscript].arrProducts[nProductSubscript].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)
Minimum version required
  • Version 10
This page is also available for…
Comments
Click [Add] to post a comment