- Delphi Cookbook
- Daniele Spinetti Daniele Teti
- 323字
- 2025-04-04 16:22:46
There's more...
In JSON objects, the Owned property determines whether the parent is responsible for the destruction of the object. This property by default is True, meaning all contained instances are owned by their parent. This is why, usually, if you have a combination of various JSON objects, you free only the last parent.
Although not the fastest or the most standards-compliant on the market, JSON usability is important because other Delphi technologies, such as DataSnap, use it. Luckily, there are a lot of alternative JSON parsers for Delphi, if you find you have trouble with the standard one.
Other notable JSON parsers are the following:
- SuperObject (https://github.com/hgourvest/superobject)
- The one included in Delphi Web Script library can be found at https://bitbucket.org/egrange/dwscript/
- A fast JSON parser from Andreas Hausladen can be found at https://github.com/ahausladen/JsonDataObjects
If your main concern is speed, then check out these alternative JSON parsers.
There are also a lot of serialization libraries that use JSON as a serialization format. In general, every parser has its own way to serialize an object to JSON. Find your favorite. Just as an example, in Chapter 5, The Thousand Faces of Multithreading, in the Using tasks to make your customer happy recipe, you will see an open source library containing a set of serialization helpers using the default Delphi JSON parser.
However, JSON is not the right tool for every interchange or data-representation job. XML has been creating other technologies that can help if you need to search, transform, and validate your data in a declarative way. In JSON land, there is no such level of standardization, apart from the format itself. However, over the years, there has been an effort to include at least the XML schema counterpart in JSON, and you can find more details at http://json-schema.org/.