GetChildKey

Description

Gets the key name of the child item in a JSON parser object.

Applies to

JSONParser objects

Syntax

objectname.GetChildKey ( ParentItemHandle, Index )
objectname.GetChildKey ( ParentItemPath, Index )

Argument

Description

objectname

The name of the JSONParser object whose key name you want to obtain.

ParentItemHandle

A long whose value is the handle of the parent item of JsonObjectItem type.

ParentItemPath

A string whose value is the path of the parent item of JsonObjectItem 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

String.

Returns the key name of the child item if it succeeds and empty string ("") if an error occurs. If any argument's value is null, the method returns null.

Examples

This example gets the key of the child item according to the parent item handle and the child item index:

JsonParser lnv_JsonParser
Long ll_RootObject, ll_id
String ls_Json, ls_key, ls_name
boolean lb_active
lnv_JsonParser = Create JsonParser

ls_Json = '{"id":1001, "name":"evan", "active":true}'

// Loads a JSON string
lnv_JsonParser.LoadString(ls_Json)
ll_RootObject = lnv_JsonParser.GetRootItem()

// Gets the key of the child item
ls_key = lnv_JsonParser.GetChildKey(ll_RootObject, 1)
ll_id = lnv_JsonParser.GetItemNumber(ll_RootObject, ls_key)
ls_key = lnv_JsonParser.GetChildKey(ll_RootObject, 2)
ls_name = lnv_JsonParser.GetItemString(ll_RootObject, ls_key)
ls_key = lnv_JsonParser.GetChildKey(ll_RootObject, 3)
lb_active = lnv_JsonParser.GetItemBoolean(ll_RootObject, ls_key)

This example gets the key of the child item according to the parent item path and the child item index:

JsonParser lnv_JsonParser
Long ll_id
String ls_Json, ls_key, ls_name, ls_RootPath, ls_ChildPath
boolean lb_active
lnv_JsonParser = Create JsonParser

ls_Json = '{"id":1001, "name":"evan", "active":true}'

// Loads a JSON string
lnv_JsonParser.LoadString(ls_Json)
ls_RootPath = "/"

// Gets the key of the child item
ls_key = lnv_JsonParser.GetChildKey(ls_RootPath, 1)
ls_ChildPath = ls_RootPath + ls_Key
ll_id = lnv_JsonParser.GetItemNumber(ls_ChildPath)
ls_key = lnv_JsonParser.GetChildKey(ls_RootPath, 2)
ls_name = lnv_JsonParser.GetItemString(ls_RootPath + ls_key)
ls_ChildPath = "/active"
lb_active = lnv_JsonParser.GetItemBoolean(ls_ChildPath)

See also

GetChildCount

GetChildItem