ONLINE HELP
 WINDEVWEBDEV AND WINDEV MOBILE

Help / WLanguage / WLanguage functions / Standard functions / String functions
  • Example for the JSONToVariant function
JSONToVariant (Example)
Example for the JSONToVariant function
When using JSON with a fixed content, you can declare only once the WLanguage structures that are filled by a JSON deserialization with Deserialize.
However, when using a JSON whose content can change, it must be read in order to retrieve all its members and values. When the JSON file is read, it is converted to a variant. This code explains how to perform a "generic" browse on the variant loaded by JSON.
sJSon is ANSI string = [
{
"Member1": "Value Member 1",
"Member2": "Value Member 2",
"Member3": "Value Member 3",
"Member 4": {
"Member 5": {
"Member 6": 6,
"Member 7": "Value Member 7"
},
"Member 8": {
"Member 9":  9,
"Member 10": "Value Member 10"
}
}
}
]
 
let vjs = JSONToVariant(sJSon)
 
FOR EACH _Member OF vjs..Member
 
IF _Member..Member..Count = 0 THEN
Trace("The member " + _Member..Name + " has the value " + _Member..Value)
ELSE
Trace("The member " + _Member..Name + " has " + _Member..Member..Count + ...
" other members")
BrowseVariantMembers(_Member)
END
END
 
INTERNAL PROCEDURE BrowseVariantMembers(x)
 
FOR EACH _Member OF x..Member
IF _Member..Member..Count = 0 THEN
Trace(Repeat("--", StringCount(dbgInfo(dbgStack), CR)) + ...
"The member " + _Member..Name + " has the value " + _Member..Value)
ELSE
Trace(Repeat("--", StringCount(dbgInfo(dbgStack), CR)) + ...
"The member " + _Member..Name + " has " + _Member..Member..Count + ...
 " other members...")
BrowseVariantMembers(_Member)
END
END
END
Minimum version required
  • Version 19
This page is also available for…
Comments
Ler Jason e Adicionar Tabela - JSONVersVariant
https://windevdesenvolvimento.blogspot.com/2017/02/aula-1053-windev-json-2-ler-jason-e.html

https://youtu.be/fY9AtlEkY-8


De matos
12 May 2019

Last update: 05/26/2022

Send a report | Local help