GetChildItem

Description

Gets the handle of the child item in a JSON parser object.

Applies to

JSONParser objects

Syntax

objectname.GetChildItem ( ParentItemHandle, 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 and JsonArrayItem type.

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:

JsonParser lnv_JsonParser
String ls_Json,ls_name,ls_deptname
Long ll_id, ll_number
Boolean lb_sex
lnv_JsonParser = create JsonParser

ls_Json = '{"id":1001, "name":"evan", "sex":true, "department_array":[999999, {"name":"Website"}, {"name":"PowerBuilder"}, {"name":"IT"}]}'

// Loads a JSON string
lnv_JsonParser.LoadString(ls_Json)
Long 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_sex = lnv_JsonParser.GetItemBoolean(ll_RootObject, "sex")

// Get the child item of department_array
Long ll_department_array = lnv_JsonParser.GetItemArray(ll_RootObject, "department_array")
Long ll_number_item = lnv_JsonParser.GetChildItem(ll_department_array, 1)
ll_number = lnv_JsonParser.GetItemNumber(ll_number_item)
Long ll_object_item = lnv_JsonParser.GetChildItem(ll_department_array, 2)
ls_deptname = lnv_JsonParser.GetItemString(ll_object_item, "name")
……

See also

GetChildCount

GetChildKey