PC SOFT

ONLINE HELP
FOR WINDEV, WEBDEV AND WINDEV MOBILE

Home | Sign in | English US
  • 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..Occurrence = 0 THEN
Trace("The member " + _Member..Name + " has the value " + _Member..Value)
ELSE
Trace("The member " + _Member..Name + " has " + _Member..Member..Occurrence + ...
" other members")
BrowseVariantMembers(_Member)
END
END

INTERNAL PROCÉDURE BrowseVariantMembers(x)

FOR EACH _Member OF x..Member
IF _Member..Member..Occurrence = 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..Occurrence + ...
 " other members...")
BrowseVariantMembers(_Member)
END
END
END
Minimum required version
  • 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
May 12 2019