| json - JSON handle to test |
|
Returns true only for a real JSON null value. JSON separates three ideas that games often blur together, and JsonIsNull is how you tell them apart: 1. The field exists and is deliberately empty - "guild": null in the save. JsonObjectGet returns a positive handle and JsonIsNull returns true. 2. The field does not exist at all - JsonObjectGet returns 0. Do not call JsonIsNull on that: 0 is not a handle, and passing it is a programming error. 3. The field exists with a real value - JsonIsNull returns false. It is a convenience for JsonKind(json)=JSON_NULL, and false for every other kind including Boolean false, 0 and an empty string. Nulls are created with CreateJsonNull or parsed from the literal null. For the full rules, see the Application Data language reference. See also: CreateJsonNull, JsonKind, JsonObjectGet, JsonObjectHas. |
; JsonIsNull Example
; ------------------
q$=Chr(34) ; Double-quote character, for building JSON text
; This hero has no guild yet - the save stores null for it
save=ParseJson("{"+q+"player"+q+":"+q+"Aria"+q+","+q+"guild"+q+":null}")
; JsonIsNull is true only for a real JSON-null handle
guild=JsonObjectGet(save,"guild")
Print "guild handle = "+guild+" (a real handle, not zero)"
Print "JsonIsNull(guild) = "+JsonIsNull(guild)
player=JsonObjectGet(save,"player")
Print "JsonIsNull(player) = "+JsonIsNull(player)+" ("+JsonText(player)+" is a string)"
Print ""
If JsonIsNull(guild)
Print "Aria has not joined a guild yet."
EndIf
FreeJson player
FreeJson guild
FreeJson save
Print ""
Print "Press any key to close the example"
WaitKey
End