Skip to content

Instantly share code, notes, and snippets.

@seanbamforth
Created February 2, 2025 14:19
Show Gist options
  • Save seanbamforth/aa0750df1aba99706ff005eae0e0ccbd to your computer and use it in GitHub Desktop.
Save seanbamforth/aa0750df1aba99706ff005eae0e0ccbd to your computer and use it in GitHub Desktop.
Use cJSONObject for a basic key/value Dictionary Class.
Object oDictJSON is a cObject
Property Handle phJSON
Function JSONHandle Returns Handle
Handle hObj
Get phJSON to hObj
If (hObj=0) Begin
Get Create (RefClass(cJsonObject)) to hObj
Send InitializeJsonType of hObj jsonTypeObject
Set phJSON to hObj
End
Function_Return hObj
End_Function
Procedure AddKey String sKey String sValue
Handle hObj
Get JSONHandle to hObj
Send SetMemberValue of hObj sKey jsonTypeString sValue
End_Procedure
Procedure RemoveAll
Handle hObj
Get JSONHandle to hObj
Send InitializeJsonType of hObj jsonTypeObject
End_Procedure
Procedure Delete_data
Send RemoveAll
End_Procedure
Function KeyValueExists String sKey Returns Boolean
Handle hObj
Get JSONHandle to hObj
Function_Return (HasMember (hObj,sKey))
End_Function
Function KeyValue String sKey Returns String
Handle hObj
Get JSONHandle to hObj
If (HasMember (hObj,sKey)) Function_Return (MemberValue(hObj,sKey))
Else Function_Return ""
End_Function
Function DefaultedKeyValue String sKey String sDefault Returns String
Handle hObj
Get JSONHandle to hObj
If (HasMember (hObj,sKey)) Function_Return (MemberValue(hObj,sKey))
Else Function_Return sDefault
End_Function
Function SizeOfDictionary Returns Integer
Handle hObj
Get JSONHandle to hObj
Function_Return (MemberCount(hObj))
End_Function
End_Object
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment