I recently updated my JSON-Library. Both, IJSONObject and IJSONArray now have methods to check for the type of the nested items.
IJSONObject = interface ['{D00A665F-3CBB-4DDB-8300-FB8020DA564B}'] . . . function isJSONObject(aKey : string) : boolean; function isJSONArray(aKey : string) : boolean; function isString(aKey : string) : boolean; function isInteger(aKey : string) : boolean; function isBoolean(aKey : string) : boolean; function isDouble(aKey : string) : boolean; end; IJSONArray = interface ['{B120D59A-1D00-469E-97CE-AE2A635A51ED}'] . . . function isJSONObject(aIndex : integer) : boolean; function isJSONArray(aIndex : integer) : boolean; function isString(aIndex : integer) : boolean; function isInteger(aIndex : integer) : boolean; function isBoolean(aIndex : integer) : boolean; function isDouble(aIndex : integer) : boolean; end;Usage:
var jo : IJSONObject; begin jo := TJSON.NewObject('{"string":"abc", "integer":123}'); jo.isString('string'); // true jo.isInteger('integer'); // true jo.isBoolean('string'); // false end;The implementation is very strict, e.g. isDouble will return false if the value is an integer and could be accessed as a double. I also included unit tests to cover these methods.
Keine Kommentare:
Kommentar veröffentlichen