Delphi and SuperObject JSON support have a very different implementation
Posted by jpluimers on 2020/12/09
In the comments of [WayBack] Delphi and JSON Is there an overlay (eg in the form of a helper) for the JSON classes built into Delphi (System.JSON), which offered an interface simil… – Jacek Laskowski – Google+
SuperObject has a very different implementation for JSON support than the Delphi RTL System.JSON unit as explained by Dalija Prasnikar:
If you are thinking about replacing existing code that uses SuperObject with Delphi build in JSON library, you have another problem on desktop – non-ARC compiler. SuperObject classes are interface based (reference counted) and Delphi JSON is class based – non ref-counted.
These methods are not in the Delphi RTL because of the difference:
How to read a property value of an object ?
val := obj.AsObject.S['foo']; // get a string val := obj.AsObject.I['foo']; // get an Int64 val := obj.AsObject.B['foo']; // get a Boolean val := obj.AsObject.D['foo']; // get a Double val := obj.AsObject.O['foo']; // get an Object (default) val := obj.AsObject.M['foo']; // get a Method val := obj.AsObject.N['foo']; // get a null objectHow to read a value from an array ?
// the advanced way val := obj.AsArray.S[0]; // get a string val := obj.AsArray.I[0]; // get an Int64 val := obj.AsArray.B[0]; // get a Boolean val := obj.AsArray.D[0]; // get a Double val := obj.AsArray.O[0]; // get an Object (default) val := obj.AsArray.M[0]; // get a Method val := obj.AsArray.N[0]; // get a null object
–jeroen
Leave a Reply