To parse JSON in Delphi, you can use the TJsonObject class from the System.JSON unit of the Delphi RTL. This class provides properties and methods that allow you to parse a JSON string and access the values of the JSON properties.
Here is an example of how you can use the TJsonObject class in Delphi to parse a JSON string;
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
uses System.SysUtils, System.JSON; var JSON string; JsonObject TJsonObject; Name string; Age Integer; begin JSON = ‘{name John Doe, age 35}’; //Parse the JSON string JsonObject = TJsonObject.ParseJSONValue(JSON) as TJsonObject; try //Get the values of the JSON properties Name = JsonObject.GetValuestring(‘name’); Age = JsonObject.GetValueInteger(‘age’); //Print the values Writeln(‘Name ‘, Name); Writeln(‘Age ‘, Age); finally JsonObject.Free; end; end. |
This code sample uses the TJsonObject class to parse a JSON string and access the values of the JSON properties.
Leave a Reply