ContainsPath
PowerScript function
Description
Checks if the path exists.
Applies to
Syntax
|
1 |
objectname.ContainsPath ( ItemPath ) |
|
Argument |
Description |
|---|---|
|
objectname |
The name of the JSONParser object whose path you want to |
|
ItemPath |
A string whose value is the path of the item of |
Return value
Boolean. Returns true if the item path exists and false if an error
occurs. If any argument’s value is null, the method returns null.
Example 1
This example loads a JSON string into a JSONParser object and checks
if the specified path exists:
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
String ls_Return, ls_Path Boolean lb_Contains JSONItemType ljit_Dept JsonParser ljp_ContainsPath ljp_ContainsPath = Create JsonParser // Loads JSON string to JSONParser object ls_Return = ljp_ContainsPath.LoadString ( '{"Boolean":false, "Name":"A&DName", "object":{"1":"1"}, "dept":[{"dept_id":100, "dept_name":"R & D8", "dept_head_id":105}, {"dept_id":200, "dept_name":"Sales", "dept_head_id":129}]}' ) If Trim(ls_Return)<>"" Then // Prints the error message Return End If // Checks if JSONParser parent node contains a Boolean path // This script returns TRUE ls_Path = "/Boolean" lb_Contains = ljp_ContainsPath.ContainsPath( ls_Path ) ls_Path = "/dept" lb_Contains = ljp_ContainsPath.ContainsPath( ls_Path ) If lb_Contains Then ljit_Dept = ljp_ContainsPath.getitemtype( ls_Path ) If ljit_Dept = JsonArrayItem! Then // Checks if the first element contains a dept_name path // This script returns TRUE ls_Path = "/dept/1/dept_name" lb_Contains = ljp_ContainsPath.ContainsPath( ls_Path ) // Checks if the first element contains a Boolean path // This script returns FALSE ls_Path = "/dept/1/Boolean" lb_Contains = ljp_ContainsPath.ContainsPath( ls_Path ) Else // Prints error message: the dept path is JsonArrayItem End If Else // Prints the error message End If |
See also
Document get from Powerbuilder help
Thank you for watching.
Subscribe
Login
0 Comments
Oldest