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
AndroidC++BuilderDelphiDemoFiremonkeyWindows

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

AndroidC++BuilderCode SnippetDelphiDemoFiremonkeyIOSOSXShowcaseWindows

Powerful Cross Platform Email App Sample In Delphi 10.4.1 FireMonkey For Android And IOS

AndroidC++BuilderDelphiFiremonkeyIOSOSXWindows

Significant Update Available For Delphi FireMonkey 10.4.1 On Android, IOS, OSX, Windows, And Linux

C++BuilderDelphiIDEWindows

Professional SVG Icon Image List For Delphi 10.4 FireMonkey On Windows

Sign up for our Newsletter and
stay informed

Leave a Reply