|
|
|
|
|
- Example for the JSONToVariant function
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
This page is also available for…
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|