Description
Gets the handle of the child item in a JSON parser object.
Applies to
Syntax
objectname.GetChildItem ( ParentItemHandle, Index )
objectname.GetChildItem ( ParentItemPath, Index )
Argument |
Description |
---|---|
objectname |
The name of the JSONParser object whose item handle you want to obtain. |
ParentItemHandle |
A long whose value is the handle of the parent item of JsonObjectItem or JsonArrayItem type. |
ParentItemPath |
A string whose value is the path of the parent item of JsonObjectItem or JsonArrayItem type. If a key name contains "/", use the escape character "~~/" to replace "/". |
Index |
A long whose value is the index of the child item. |
Return value
Long.
Returns the handle of the child item if it succeeds and -1 if an error occurs. If any argument's value is null, the method returns null.
Examples
This example gets the child item of department_array according to the parent item handle and the child item index:
JsonParser lnv_JsonParser lnv_JsonParser = create JsonParser String ls_Json, ls_name, ls_deptname Long ll_id, ll_number Long ll_RootObject, ll_department_array, ll_number_item, ll_object_item Boolean lb_active ls_Json = '{"id":1001, "name":"evan", "active":true, "department_array":[999999, {"name":"Website"}, {"name":"PowerBuilder"}, {"name":"IT"}]}' // Loads a JSON string lnv_JsonParser.LoadString(ls_Json) ll_RootObject = lnv_JsonParser.GetRootItem() // Gets the root item ll_id = lnv_JsonParser.GetItemNumber(ll_RootObject, "id") ls_name = lnv_JsonParser.GetItemString(ll_RootObject, "name") lb_active = lnv_JsonParser.GetItemBoolean(ll_RootObject, "active") // Get the child item of department_array ll_department_array = lnv_JsonParser.GetItemArray(ll_RootObject, "department_array") ll_number_item = lnv_JsonParser.GetChildItem(ll_department_array, 1) ll_number = lnv_JsonParser.GetItemNumber(ll_number_item) ll_object_item = lnv_JsonParser.GetChildItem(ll_department_array, 2) ls_deptname = lnv_JsonParser.GetItemString(ll_object_item, "name") …
This example gets the child item of department_array according to the parent item path and the child item index:
JsonParser lnv_JsonParser lnv_JsonParser = create JsonParser String ls_Json, ls_name, ls_deptname, ls_RootPath, ls_ChildPath Long ll_id, ll_number Long ll_number_item, ll_object_item Boolean lb_active ls_Json = '{"id":1001, "name":"evan", "active":true, "department_array":[999999, {"name":"Website"}, {"name":"PowerBuilder"}, {"name":"IT"}]}' // Loads a JSON string lnv_JsonParser.LoadString(ls_Json) ls_RootPath = "/" // Gets the root item ll_id = lnv_JsonParser.GetItemNumber(ls_RootPath + "id") ls_name = lnv_JsonParser.GetItemString("/name") lb_active = lnv_JsonParser.GetItemBoolean("/active") // Get the child item of department_array ls_ChildPath = ls_RootPath + "department_array" ll_number_item = lnv_JsonParser.GetChildItem(ls_ChildPath, 1) ll_number = lnv_JsonParser.GetItemNumber(ll_number_item) ll_object_item = lnv_JsonParser.GetChildItem("/department_array", 2) ls_deptname = lnv_JsonParser.GetItemString(ll_object_item, "name")
See also