Home How can I convert JSON into a list using REST.Json in Delphi?
Reply: 1

How can I convert JSON into a list using REST.Json in Delphi?

Fernando Vallim
Fernando Vallim Published in 2018-02-08 12:40:12Z

I have a JSON file like this:

[{"id":1,"name":"JOHN"}, {"id":2,"name":"PETER"}]

I want to store this list into a ClientDataSet, or something like that. How can I do this in Delphi 10.2 Tokyo using the REST.Json unit?

loki Reply to 2018-02-08 15:03:33Z

Using Rest.json, i don't know but if you want to convert [{"id":1,"name":"JOHN"}, {"id":2,"name":"PETER"}] to a Tstringlist you can do it in one line using alcinoe

Procedure ALJSONToTStrings(const AJsonStr: AnsiString;
                           const aFormatSettings: TALFormatSettings;
                           const aPath: AnsiString;
                           const aLst: TALStrings;
                           Const aNullStr: AnsiString = 'null';
                           Const aTrueStr: AnsiString = 'true';
                           Const aFalseStr: AnsiString = 'false'); overload;

Procedure ALJSONToTStringsU(const AJsonStr: String;
                            const aFormatSettings: TALformatSettingsU;
                            const aPath: String;
                            const aLst: TALStringsU;
                            Const aNullStr: String = 'null';
                            Const aTrueStr: String = 'true';
                            Const aFalseStr: String = 'false'); overload;
You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.298209 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO