GetItemByPath
PowerScript function
Description
Gets the handle of the item.
Applies to
JSONParser
objects and JSONGenerator objects
Syntax
|
1 |
objectname.GetItemByPath ( ItemPath ) |
|
Argument |
Description |
|---|---|
|
objectname |
The name of the JSONParser or JSONGenerator object whose |
|
ItemPath |
A string specifying the path of the item. If there is a |
Return value
Long.
Returns the item handle if it succeeds and -1 if an error occurs. If
any argument’s value is null, returns null.
Example 1
This example gets the item handle from a JSONParser object according
to the item path from a one-dimensional array:
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
JsonParser lnv_JsonParser String ls_Json, ls_Name, ls_Path DateTime ldt_DateTime Long ll_item lnv_JsonParser = Create JsonParser ls_Json = '{"id":1001, "name":"evan", "data_object":{"datetime":7234930293, "date": "2017-09-21", "time": "12:00:00","age":[55,22,33]}}' lnv_JsonParser.LoadString(ls_Json) ls_Path = "/name" ll_item = lnv_JsonParser.GetItemByPath(ls_Path) ls_Name = lnv_JsonParser.GetItemString(ll_item) ls_Path = "/data_object/datetime" ll_item = lnv_JsonParser.GetItemByPath(ls_Path) ldt_DateTime = lnv_JsonParser.GetItemDateTime(ll_item) |
Example 2
This example gets the item handle from a JSONParser object according
to the item path from a two-dimensional array. The number indicates the
order of the array.
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
JsonParser lnv_JsonParser String ls_Json, ls_Name, ls_Path DateTime ldt_DateTime Long ll_item lnv_JsonParser = Create JsonParser ls_Json = '[{"id":1001, "name":"evan", "data_object":{"datetime":7234930293, "date": "2017-09-21", "time": "12:00:00","age":[66,22,33]}},' + & '{"id":1002, "name":"evan2", "data_object":{"datetime":1734930293, "date": "2017-09-11", "time": "11:00:00","age":[55,23,33]}}]' lnv_JsonParser.LoadString(ls_Json) ls_Path = "/1/name" ll_item = lnv_JsonParser.GetItemByPath(ls_Path) ls_Name = lnv_JsonParser.GetItemString(ll_item) ls_Path = "/2/data_object/datetime" ll_item = lnv_JsonParser.GetItemByPath(ls_Path) ldt_DateTime = lnv_JsonParser.GetItemDateTime(ll_item) |
Example 3
This example determines the item handle in a JSONGenerator object
according to the item path and then adds three child items:
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
Long ll_ChildObject String ls_RootPath,ls_ChildPath JsonGenerator lnv_JsonGenerator lnv_JsonGenerator = Create JsonGenerator // Creates an object root item lnv_JsonGenerator.CreateJsonObject () // Adds an object child item ls_RootPath = "/" lnv_JsonGenerator.AddItemObject(ls_RootPath, "object") ls_ChildPath = "/object" ll_ChildObject = lnv_JsonGenerator.GetItemByPath(ls_ChildPath) 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) |
See also
GetPathByItem
(JSONGenerator)