Class Union |
A singleton class supporting conversions to/from UniON (Unicon Object Notation). Heavily based on the JSON support by Gigi Young found in json.icn. Note that UniON is not JSON, although it shares many characteristics. In particular, Unicon structures are uniquely identified by structure type in UniON which does not correspond to any JSON structure encode (i.e. they are not treated as dictionaries). So UniON is not suitable for inter-language information exchange but only for information exchange between Unicon applications. If you need inter-language information exchange, see json.icn.
Any Unicon value, including structures containing cyclical references, can be (in theory) converted to/from UniON. Report a bug if that's not the case. For example, the following (absurd) code outputs SAME.
t := table() t[t] := t y := Union().decode(Union().encode(t)) write(if equals(t,y) then "SAME" else "DIFFERENT")
The following example, pulled from property.icn, illustrate a more pratical use of the Union class:
#<p> # Store a property's value into a database. # <[param pName name of the property]> # <[param value value for the named property]> #</p> method setP(pName, value) pdb.store(pName, Union().encode(value)) end #<p> # Produce a property's value from a database. # <[param pName name of the property]> # <[return the current value of the named property]> #</p> method getP(pName) return Union().decode(getPString(pName)) end
Details |
Constructor |
Methods: |
s | UniON-encoded string |
unicon entity that was encoded in s |
Convert a UniON string into the equivalent unicon entity.
x | Unicon value to encode into UniON |
Given a Unicon value, produce a UniON equivalent if possible.