AddJSONElement()

语法

Result = AddJSONElement(JSONValue [, Index])
概要
Add a new array element to a JSON value of type #PB_JSON_Array.

参数

JSONValue The JSON value. The value must be of type #PB_JSON_Array.
Index (optional) The index at which the new value will be inserted into the array. If the index is outside of the range of the array, the new value will be inserted either at the start (for Index < 0) or the end of the array. If this parameter is not specified, the new value is added at the end of the array.

返回值

Returns the address of the added JSON value. The newly added value initially has type #PB_JSON_Null.

示例

  If CreateJSON(0)
    ArrayValue = SetJSONArray(JSONValue(0))
    
    ; add element at the end
    For i = 1 To 5
      NumValue = AddJSONElement(ArrayValue)
      SetJSONInteger(NumValue, i)
    Next i
    
    ; insert at a specific index
    StrValue = AddJSONElement(ArrayValue, 1)
    SetJSONString(StrValue, "Hello")
    
    Debug ComposeJSON(0)
  EndIf

参阅

SetJSONArray(), RemoveJSONElement(), ResizeJSONElements(), ClearJSONElements(), GetJSONElement(), JSONArraySize(), JSONType()

已支持操作系统

所有

Json Index - AddJSONMember() ->