Blitz3D+ Command Reference

JsonObjectClear json

Parameters

json - JSON object handle to empty

Description

Removes every property from an object.

The "New Game" button of the JSON family: one call wipes a save-game record or settings block back to an empty object while keeping the object itself - the handle stays valid, its JsonCount drops to 0, and it is ready to be refilled with JsonObjectSet. That is usually tidier than freeing the document and rebuilding it, especially when the handle is stored somewhere long-lived.

Copies of former properties fetched earlier with JsonObjectGet stay valid - they are independent of the parent. Clearing an already-empty object is a harmless no-op; calling JsonObjectClear on a non-object is a programming error.

For the full rules, see the Application Data language reference.

Requires Extended mode.

See also: JsonObjectRemove, JsonObjectSet, JsonArrayClear, CreateJsonObject, FreeJson.

Example

; JsonObjectClear Example
; -----------------------
; Requires Extended mode.

q$=Chr(34)  ; Double-quote character, for building JSON text

; The player chose "New Game" - wipe the old save-game record
save=ParseJson("{"+q+"player"+q+":"+q+"Aria"+q+","+q+"level"+q+":7,"+q+"gold"+q+":1250}")

Print "Old save:  "+JsonStringify(save,0)
Print "Field count: "+JsonCount(save)
Print ""

; JsonObjectClear removes every property but keeps the object itself
JsonObjectClear save

Print "After clear: "+JsonStringify(save,0)
Print "Field count: "+JsonCount(save)
Print ""

; The same handle is ready for a fresh adventure
v=CreateJsonString("Brom")
JsonObjectSet save,"player",v
FreeJson v
Print "New game:  "+JsonStringify(save,0)

FreeJson save

Print ""
Print "Press any key to close the example"
WaitKey

End

Index