Description
Gets the type of the number item.
Applies to
Syntax
objectname.GetNumberType ( ItemHandle )
objectname.GetNumberType ( ParentItemHandle, Key )
objectname.GetNumberType ( ItemPath )
|
Argument |
Description |
|---|---|
|
objectname |
The name of the JSONParser object whose item type you want to obtain. |
|
ItemHandle |
A long specifying the item handle which is JsonNumberItem type. |
|
ParentItemHandle |
A long specifying the parent item handle which is JsonObjectItem type. |
|
Key |
A string specifying the key of the child item which is JsonNumberItem type. |
|
ItemPath |
A string specifying the item path which is JsonNumberItem type. If there is a multi-dimensional array, use the number to indicate the order of the array elements. If a key name contains "/", use the escape character "~~/" to replace "/". |
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:
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:
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:
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


