JSON Parser Xojo plugin

JSONPrimitive.FromVariant Method

Generates JSON structure from a variant.

shared FromVariant(
   value as Variant) as JSONPrimitive

Parameters

value
The variant value to convert.

Returns

JSONPrimitive

Remarks

It will make JSON object from Xojo Dictionary and JSONArray from Xojo Arrays.

Colors get converted to string representation of the color. And Dates are converted to ISO-8601 string formatted date.

Example: The following code will generate JSON structure from complex variant structure


using EinhugurJSON

Dim d as Dictionary = new Dictionary()
Dim d2 as new Dictionary()

Dim s(2) as Integer
s(0) = 5
s(1) = 6

Dim col as Color = &cFF0000
d.Value("Key1") = "Test1"
d.Value("Key2") = "Test2"
d.Value("Key22") = "Test3"
d.Value("Key3") = d2
d.Value("Key4") = col


d2.Value("K1") = 50
d2.Value("K2") = 127127.3
d2.Value("K3") = new Date()
d2.Value("K4") = &cFF0000
d2.Value("K5") = s

Dim j as JSONPrimitive = JSONPrimitive.FromVariant(d)

MsgBox j.GetSource()



The following result is produced:

See Also

JSONPrimitive Class