PC SOFT

WINDEVWEBDEV AND WINDEV MOBILE
ONLINE HELP

Home | Sign in | English UK
  • Example for the JSONToVariant function
JSONToVariant (Example)
Example for the JSONToVariant function
When using JSON with a fixed content, you have the ability to declare once and for all the WLanguage structures that are filled by a JSON deserialization with Deserialize.
However, when exploiting a JSON whose content can change, it must be browsed in order to retrieve all its members and values. The browse is performed by transferring the JSON into 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