Get access to over 100 FireMonkey cross platform samples for Android, IOS, OSX, Windows, and Linux!

AndroidAppmethodCode SnippetDelphiDemoFiremonkeyIOSOSXWindows

Four Ways To Parse JSON Into Objects With Delphi XE6 Firemonkey On Android And IOS

Delphi XE6 Firemonkey Parse JStephen Bell from Embarcadero recently posted a blog post on how to parse JSON with a single line of code in Delphi XE6 Firemonkey. I had to parse some JSON recently myself and I wanted to try out some different ways of doing that as I usually use XSuperObject. I came up with four different ways to parse out a piece of JSON. Some of the ways are completely static and one of them is completely dynamic. The four ways I tried are the TJson.JsonToObject way into a custom object, using the straight XSuperObject way into a custom object, using XSuperObject into a generic Tuple, and using XSuperObject into a dynamic TStringList. When I parse the JSON I put the object that I create to store the data in into a TStringList for usage later. Full source code for a sample project demonstrating each way is available at the bottom. All four ways will probably also work in Delphi XE5 and AppMethod in addition to cross platform on Windows, OSX, Android, and IOS.

Here is the straight XSuperObject into a custom object. This way is pretty static and requires that you define an object, TPizza, in the type section:

Here is the TJson.JsonToObject into a custom object. This way takes less code than the direct XSuperObject way but still requires that you define an object, TPizza, in the type section:

And here is reading both of the above back out from the TPizza object:

Here is the XSuperObject into a Tuple. For me this code is harder to read but does not require that you define the extra TPizza object type at the top of the unit:

And finally here is the XSuperObject into a TStringList. For me this seems like the most dynamic way. There are no predefined names hard coded into your code and it supports an unlimited number of name value pairs. However, it does only support string types and probably takes up some more memory than some of the other ways:

Download the full source code for the four different ways to parse JSON with Delphi XE6 Firemonkey.


Have Delphi Firemonkey questions? Ask and get answers on StackOverflow.

Related posts

FireMonkey 10.4.2 Features Updated iOS 14, Android 11, And macOS 11 Support Plus Hundreds Of Fixes


Ryzen 9 5950x: One Billion Lines Of Delphi Code Compiled In ~5 Minutes On 16 Cores


DelphiCon 2020 FireMonkey Sessions Available Starting November 19


Powerful Commercial Gorilla3D Framework Upgraded For Delphi FireMonkey On Windows And Android

Sign up for our Newsletter and
stay informed

Leave a Reply