I cannot seem to generate an array of named objects using JSONGenerator.
If I use the following code:
Jsongenerator jga
Long ll_child
Long ll_jsonarray
long ll_handle
long ll_root
String ls_json1
jga = create JSONGenerator
ll_root = jga.CreateJsonObject()
ll_jsonarray = jga.AddItemArray(ll_root, "packages")
ll_child = jga.AddItemobject(ll_jsonarray)
ll_handle = jga.AddItemNumber(ll_child,"value", 4.5)
ll_handle =jga.AddItemString(ll_child,"unit", "pound")
ll_child = jga.AddItemobject(ll_jsonarray)
ll_handle = jga.AddItemNumber(ll_child,"value", 6.8)
ll_handle =jga.AddItemString(ll_child,"unit", "pound")
ls_json1 = jga.getjsonstring( )
I get these results:
{
"packages":
[
{"value":4.5,"unit":"pound"},
{"value":6.8,"unit":"pound"}
]
}
Which is close to what I need but what I really want is:
{
"packages":
[
{ "weight": {"value":4.5,"unit":"pound"} },
{ "weight": {"value":6.8,"unit":"pound"} }
]
}
So it seemed logical to change my AddItemObject statement from
ll_child = jga.AddItemobject(ll_jsonarray)
to this:
ll_child = jga.AddItemobject(ll_jsonarray, "weight")
but when I do that I get:
{"packages":[]}
Is there a way to get the generator to create more complex json or is it just a bit too primitive a tool to get the output I need?