JsonArrayClear json
Parameters
| json - JSON array handle to empty |
Description
|
Removes every element from an array. One call empties the whole list - a cursed chest wipes the inventory, a "clear scores" button resets the leaderboard, a quest log is emptied for a new chapter. The array itself survives: the handle stays valid, its JsonCount drops to 0, and it is ready to be refilled with JsonArrayAppend. That is usually tidier than freeing and recreating the array, especially when the handle is already stored inside a bigger document. Copies of former elements fetched earlier with JsonArrayGet stay valid - they are independent of the parent. Clearing an already-empty array is a harmless no-op; calling JsonArrayClear on a non-array is a programming error. For the full rules, see the Application Data language reference. Requires Extended mode. See also: JsonArrayRemove, JsonArrayAppend, JsonObjectClear, CreateJsonArray, FreeJson. |
Example
; JsonArrayClear Example ; ---------------------- ; Requires Extended mode. q$=Chr(34) ; Double-quote character, for building JSON text ; The hero's inventory, moments before a cursed chest empties it inventory=ParseJson("["+q+"sword"+q+","+q+"shield"+q+","+q+"potion"+q+"]") Print "Before the curse: "+JsonStringify(inventory,0) Print "Item count: "+JsonCount(inventory) Print "" ; JsonArrayClear removes every element but keeps the array itself JsonArrayClear inventory Print "After the curse: "+JsonStringify(inventory,0) Print "Item count: "+JsonCount(inventory) Print "" Print "The array handle is still valid - ready to collect new loot." FreeJson inventory Print "" Print "Press any key to close the example" WaitKey End
Index