Description
Adds a child item of JsonObjectItem type in the JSON generator object.
Applies to
Syntax
objectname.AddItemObject ( ParentItemHandle )
objectname.AddItemObject ( ParentItemHandle, Key )
objectname.AddItemObject ( ParentItemPath )
objectname.AddItemObject ( ParentItemPath, Key )
Argument |
Description |
---|---|
objectname |
The name of the JSONGenerator object in which you want to add an item |
ParentItemHandle |
A long whose value is the handle of the parent item of JsonArrayItem or JsonObjectItem type |
ParentItemPath |
A string whose value is the path of the parent item of JsonArrayItem or JsonObjectItem type |
Key |
A string whose value is the key of the child item |
Return value
Long.
Returns the handle of the new child item if it succeeds and -1 if an error occurs. If any argument's value is null, the method returns null.
Example 1
This example creates an array root item and adds an object child item. The result is [{"year":2017,"date":"2017-09-21","time":"12:00:00"}].
Long ll_RootArray, ll_ChildObject JsonGenerator lnv_JsonGenerator lnv_JsonGenerator = Create JsonGenerator // Creates an array root item ll_RootArray = lnv_JsonGenerator.CreateJsonArray() // Adds an object child item ll_ChildObject = lnv_JsonGenerator.AddItemObject(ll_RootArray) lnv_JsonGenerator.AddItemNumber(ll_ChildObject, "year", 2017) lnv_JsonGenerator.AddItemDate(ll_ChildObject, "date", 2017-09-21) lnv_JsonGenerator.AddItemTime(ll_ChildObject, "time", 12:00:00)
Example 2
This example creates an object root item and adds an object child item. The result is {"object":{"year":2017,"date":"2017-09-21","time":"12:00:00"}}.
Long ll_RootObject, ll_ChildObject JsonGenerator lnv_JsonGenerator lnv_JsonGenerator = Create JsonGenerator // Creates an object root item ll_RootObject = lnv_JsonGenerator.CreateJsonObject () // Adds an object child item ll_ChildObject = lnv_JsonGenerator.AddItemObject(ll_RootObject, "object") lnv_JsonGenerator.AddItemNumber(ll_ChildObject, "year", 2017) lnv_JsonGenerator.AddItemDate(ll_ChildObject, "date", 2017-09-21) lnv_JsonGenerator.AddItemTime(ll_ChildObject, "time", 12:00:00)
Example 3
This example creates an array root item and adds an object child item. The result is [{"year":2017,"date":"2017-09-21","time":"12:00:00"}].
String ls_RootPath, ls_ChildPath JsonGenerator lnv_JsonGenerator lnv_JsonGenerator = Create JsonGenerator // Create an array root item lnv_JsonGenerator.CreateJsonArray() ls_RootPath = "/" // Add an object child item lnv_JsonGenerator.AddItemObject(ls_RootPath) ls_ChildPath = ls_RootPath + "1" lnv_JsonGenerator.AddItemNumber(ls_ChildPath, "year", 2017) lnv_JsonGenerator.AddItemDate(ls_ChildPath, "date", 2017-09-21) lnv_JsonGenerator.AddItemTime(ls_ChildPath, "time", 12:00:00)
Example 4
This example creates an object root item and adds an object child item. The result is {"object":{"year":2017,"date":"2017-09-21","time":"12:00:00"}}.
String ls_RootPath, ls_ChildPath JsonGenerator lnv_JsonGenerator lnv_JsonGenerator = Create JsonGenerator // Creates an object root item lnv_JsonGenerator.CreateJsonObject() ls_RootPath = "/" // Adds an object child item lnv_JsonGenerator.AddItemObject(ls_RootPath, "object") ls_ChildPath = ls_RootPath + "object" lnv_JsonGenerator.AddItemNumber(ls_ChildPath, "year", 2017) lnv_JsonGenerator.AddItemDate(ls_ChildPath, "date", 2017-09-21) lnv_JsonGenerator.AddItemTime(ls_ChildPath, "time", 12:00:00)
See also