JSONType()

Syntax

Result = JSONType(JSONValue)
Description
Returns the type of the given JSON value.

Parameters

JSONValue The JSON value.

Return value

It can be one of the following:

#PB_JSON_Null
The value represents the JSON literal null.
#PB_JSON_String
The value contains a string. GetJSONString() can be used to read the string.
#PB_JSON_Number
The value contains a number. GetJSONDouble(), GetJSONFloat(), GetJSONInteger() or GetJSONQuad() can be used to read the number.
#PB_JSON_Boolean
The value contains a boolean. GetJSONBoolean() can be used to read the value.
#PB_JSON_Array
The value contains an array of JSON elements. JSONArraySize() returns the size of the array. GetJSONElement() can be used to get a specific array element. AddJSONElement(), RemoveJSONElement(), ResizeJSONElements() or ClearJSONElements() can be used to modify the array.
#PB_JSON_Object
The value contains an object (a set of key/value pairs). JSONObjectSize() returns the number of menbers in the object. GetJSONMember() returns a specific member value. ExamineJSONMembers() can be used to examine the member values. AddJSONMember(), RemoveJSONMember() or ClearJSONMembers() can be used to modify the object.

Example

  ; A procedure that accepts any JSON value and returns a string
  ;
  Procedure.s GetAnyValue(Value)
    Select JSONType(Value)
      Case #PB_JSON_Null:    ProcedureReturn "null"
      Case #PB_JSON_String:  ProcedureReturn GetJSONString(Value)
      Case #PB_JSON_Number:  ProcedureReturn StrD(GetJSONDouble(Value))    
      Case #PB_JSON_Boolean: ProcedureReturn Str(GetJSONBoolean(Value))
      Case #PB_JSON_Array:   ProcedureReturn "array"
      Case #PB_JSON_Object:  ProcedureReturn "object"
    EndSelect
  EndProcedure
  
  ParseJSON(0, "[1, 2, true, null, " + Chr(34) + "hello" + Chr(34) + "]")
  For i = 0 To JSONArraySize(JSONValue(0)) - 1
    Debug GetAnyValue(GetJSONElement(JSONValue(0), i))
  Next i

See Also

JSONValue(), SetJSONArray(), SetJSONBoolean(), SetJSONDouble(), SetJSONFloat(), SetJSONInteger(), SetJSONNull(), SetJSONObject(), SetJSONString(), SetJSONQuad()

Supported OS

All

<- JSONObjectSize() - Json Index - JSONValue() ->