Hi ,
due to lack of info in help , here I going to explain how to use Deserialize() json based on my try/error.
feel free to add if i missing anything
----------------------------------------------------------------------------------------
Deserialize(<Variable> , <Buffer> , <Parameters>)
<variable> -> variable of a structure / variable array of a structure
<Buffer> -> must be buffer not string
<Parameter> -> psdJSON
test data1:
{"Id":1,"Name":"Product"}
Test data 2:
[{"Id":1,"Name":"Manager"},{"Id":3,"Name":"Staff"},{"Id":2,"Name":"Supervisor"}]
///// declare structure ///
stA is Structure
Id is int
Name is string
END
/////////////////////////////////////////////////////////////////////////////////////////
M_Res is buffer = HTTPGetResult() ---> return utf8 buffer
/////////////// program to retrieved test data1 //////////
M_stA is stA
Deserialize(M_stA, M_Res, psdJSON)
info(m_stA.Id, m_stA.Name)
/////////////// program to retrieved test data2 //////////
M_stA is array of stA
Deserialize(M_stA, M_Res, psdJSON)
FOR EACH item OF M_stA
info(item.Id, item.Name)
END
///////////////////////////////////////conclusion//////////////////////////////////////////////////////////
1. the [ ] in json is reason to use variable array rather than variable even if only one record
2. for some reason you may had converted json buffer to string , use stringtoutf8() to convert string to buffer before Deserialize
.
due to lack of info in help , here I going to explain how to use Deserialize() json based on my try/error.
feel free to add if i missing anything
----------------------------------------------------------------------------------------
Deserialize(<Variable> , <Buffer> , <Parameters>)
<variable> -> variable of a structure / variable array of a structure
<Buffer> -> must be buffer not string
<Parameter> -> psdJSON
test data1:
{"Id":1,"Name":"Product"}
Test data 2:
[{"Id":1,"Name":"Manager"},{"Id":3,"Name":"Staff"},{"Id":2,"Name":"Supervisor"}]
///// declare structure ///
stA is Structure
Id is int
Name is string
END
/////////////////////////////////////////////////////////////////////////////////////////
M_Res is buffer = HTTPGetResult() ---> return utf8 buffer
/////////////// program to retrieved test data1 //////////
M_stA is stA
Deserialize(M_stA, M_Res, psdJSON)
info(m_stA.Id, m_stA.Name)
/////////////// program to retrieved test data2 //////////
M_stA is array of stA
Deserialize(M_stA, M_Res, psdJSON)
FOR EACH item OF M_stA
info(item.Id, item.Name)
END
///////////////////////////////////////conclusion//////////////////////////////////////////////////////////
1. the [ ] in json is reason to use variable array rather than variable even if only one record
2. for some reason you may had converted json buffer to string , use stringtoutf8() to convert string to buffer before Deserialize
.