GetNumberType
PowerScript function
Description
Gets the type of the number item.
Applies to
Syntax
|
1 |
objectname.GetNumberType ( ItemHandle ) |
|
1 |
objectname.GetNumberType ( ParentItemHandle, Key ) |
|
1 |
objectname.GetNumberType ( ItemPath ) |
|
Argument |
Description |
|---|---|
|
objectname |
The name of the JSONParser object whose item type you want |
|
ItemHandle |
A long specifying the item handle which is JsonNumberItem |
|
ParentItemHandle |
A long specifying the parent item handle which is |
|
Key |
A string specifying the key of the child item which is |
|
ItemPath |
A string specifying the item path which is JsonNumberItem |
Return value
JsonNumberType.
Returns the JsonNumberType enumerated value if it succeeds and null
value if an error occurs. If any argument’s value is null, the method
returns null.
The JsonNumberType enumerated values are:
-
JsonNumber! — Type of the JSON valid number.
-
JsonNaN! — Type of the JSON invalid number.
-
JsonPositiveInfinity! — Type of the JSON positive
infinity. -
JsonNegativeInfinity! — Type of the JSON negative
infinity.
Example 1
This example determines the type of number values according to the
item handle:
|
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 39 40 41 42 43 44 |
Long ll_ItemCount, ll_I, ll_RootItem, ll_Child String ls_Json, ls_Return, ls_Key, ls_Value Dec ldc_Value JsonItemType ljs_type, ljs_Root JsonNumberType ljsn_type Jsonparser ljs_par ljs_par = Create JsonParser ls_Json = '{"value1":123.45,"value2":Infinity,"value3":-Infinity,"value4":NaN,"value5":null}' ls_Return = ljs_par.LoadString(ls_Json) If Len(ls_Return) > 0 Then Return ll_RootItem = ljs_par.GetRootItem() ll_ItemCount = ljs_Par.GetChildCount(ll_RootItem) ljs_Root = ljs_par.GetItemType(ll_RootItem) For ll_I = 1 To ll_ItemCount ll_child = ljs_par.getchilditem( ll_RootItem, ll_i) ls_Key = ljs_par.GetChildKey(ll_RootItem, ll_i) ljs_type = ljs_par.GetItemType(ll_child) Choose Case ljs_type Case Jsonnumberitem! ldc_Value = ljs_par.GetItemNumber(ll_child) If IsNull ( ldc_value ) Then ljsn_type = ljs_par.GetNumberType(ll_child) Choose Case ljsn_type Case JsonNaN! ls_value = "Nan" Case JsonPositiveInfinity! ls_value = "Infinity" Case JsonNegativeInfinity! ls_value = "-Infinity" Case JsonNumber! ls_value = "null" Case Else End Choose Else ls_value = String(ldc_value) End If Case Jsonnullitem! ls_value = "null" End Choose ls_Return += ls_Key + "=" + ls_Value + "~r~n" Next If IsValid ( ljs_par ) Then Destroy ( ljs_par ) |
Example 2
This example determines the type of number values according to the
parent item and key name:
|
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 39 40 41 42 43 |
Long ll_ItemCount, ll_I, ll_RootItem String ls_Json, ls_Return, ls_Key, ls_Value Dec ldc_Value JsonItemType ljs_type, ljs_Root JsonNumberType ljsn_type Jsonparser ljs_par ljs_par = Create JsonParser ls_Json = '{"value1":123.45,"value2":Infinity,"value3":-Infinity,"value4":NaN,"value5":null}' ls_Return = ljs_par.LoadString(ls_Json) If Len(ls_Return) > 0 Then Return ll_RootItem = ljs_par.GetRootItem() ll_ItemCount = ljs_Par.GetChildCount(ll_RootItem) ljs_Root = ljs_par.GetItemType(ll_RootItem) For ll_I = 1 To ll_ItemCount ls_Key = ljs_par.GetChildKey(ll_RootItem, ll_i) ljs_type = ljs_par.GetItemType(ll_RootItem, ls_Key) Choose Case ljs_type Case Jsonnumberitem! ldc_Value = ljs_par.GetItemNumber(ll_RootItem, ls_Key) If IsNull ( ldc_value ) Then ljsn_type = ljs_par.GetNumberType(ll_RootItem, ls_Key) Choose Case ljsn_type Case JsonNaN! ls_value = "Nan" Case JsonPositiveInfinity! ls_value = "Infinity" Case JsonNegativeInfinity! ls_value = "-Infinity" Case JsonNumber! ls_value = "null" Case Else End Choose Else ls_value = String(ldc_value) End If Case Jsonnullitem! ls_value = "null" End Choose ls_Return += ls_Key + "=" + ls_Value + "~r~n" Next If IsValid ( ljs_par ) Then Destroy ( ljs_par ) |
Example 3
This example determines the type of number values according to the
item path:
|
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 39 40 41 42 43 44 45 46 47 48 |
Long ll_ItemCount, ll_I String ls_Json, ls_Return, ls_RootPath, ls_ChildPath, ls_Key, ls_Value Dec ldc_Value JsonItemType ljs_type, ljs_Root JsonNumberType ljsn_type Jsonparser ljs_par ljs_par = Create JsonParser ls_Json = '{"value1":123.45,"value2":Infinity,"value3":-Infinity,"value4":NaN,"value5":null}' ls_Return = ljs_par.LoadString(ls_Json) If Len(ls_Return) > 0 Then Return ls_RootPath = "/" ll_ItemCount = ljs_Par.GetChildCount(ls_RootPath) ljs_Root = ljs_par.GetItemType(ls_RootPath) For ll_I = 1 To ll_ItemCount ls_Key = ljs_par.GetChildKey(ls_RootPath, ll_i) If ljs_Root = jsonobjectitem! Then ls_ChildPath = ls_RootPath + String( ls_Key ) Else ls_ChildPath = ls_RootPath + String( ll_I ) End If ljs_type = ljs_par.GetItemType(ls_ChildPath) Choose Case ljs_type Case Jsonnumberitem! ldc_Value = ljs_par.GetItemNumber(ls_ChildPath) If IsNull ( ldc_value ) Then ljsn_type = ljs_par.GetNumberType(ls_ChildPath) Choose Case ljsn_type Case JsonNaN! ls_value = "Nan" Case JsonPositiveInfinity! ls_value = "Infinity" Case JsonNegativeInfinity! ls_value = "-Infinity" Case JsonNumber! ls_value = "null" Case Else End Choose Else ls_value = String(ldc_value) End If Case Jsonnullitem! ls_value = "null" End Choose ls_Return += ls_Key + "=" + ls_Value + "~r~n" Next If IsValid ( ljs_par ) Then Destroy ( ljs_par ) |
See also