JIMSMITH 1 Posted Sunday at 07:55 AM I am tring to read a section of json containing an array below for the section titled MAILCONFIGS. There is an array that contains two pairs. I need to read the two JSON PAIRS and breakout the datapair within. Any help will be appreciated, and Thanks in advance. { "SPWORKDATA": { "DB_PARAMS": { "Pooled":"False", "DriverID":"Oracle", "Database":"iranums", "User_name":"rms", "Password":"trojan", "Server":"lilly.com", "Port":"5432", "Monitorby":"", "MetaDefSchema":"False" }, "MAILCONFIGS": [ {"mail1@gmail.com": { "client_id": "ClientID_Data1", "apptoken": "apptoken data1", "temptoken": "temporary token1" } }, {"mail2@gmail.com": { "client_id": "client_data2", "apptoken": "apptoken data2", "temptoken": "temporary token2" } } ], "MEDIASERVER": { "Server": "192.162.2.185" }, "MSGSERVER": { "Server": "127.0.0.1", "Port":"55555" } } } Share this post Link to post
Remy Lebeau 1494 Posted Sunday at 08:26 AM (edited) What version of Delphi are you using? Delphi has had a built-in JSON framework for a long time, have you tried it yet? For example: uses ..., System.JSON; var JSON = '...'; var obj = TJSONObject.ParseJSONValue(JSON) as TJSONObject; try for var element in (obj.GetValue('MAILCONFIGS') as TJSONArray) do begin for var pair in (element as TJSONObject) do begin var email := pair.JsonString.Value; var config := pair.JsonValue as TJSONObject; var clientId := config.GetValue('client_id').Value; var appToken := config.GetValue('apptoken').Value; var tempToken := config.GetValue('temptoken').Value; ... end; end; finally obj.Free; end; If your version doesn't have it, there are plenty of 3rd party JSON libraries available. Edited Sunday at 06:32 PM by Remy Lebeau Share this post Link to post
JIMSMITH 1 Posted Sunday at 06:01 PM 9 hours ago, Remy Lebeau said: What version of Delphi are you using? Delphi has had a built-in JSON framework for a long time, have you tried it yet? For example: var JSON = '...'; var obj = TJSONObject.ParseJSONValue(JSON) as TJSONObject; try for var element in (obj.GetValue('MAILCONFIGS') as TJSONArray) do begin for var pair in (element as TJSONObject) do begin var email := pair.JsonString.Value; var config := pair.JsonValue as TJSONObject; var clientId := config.GetValue('client_id').Value; var appToken := config.GetValue('apptoken').Value; var tempToken := config.GetValue('temptoken').Value; ... end; end; finally obj.Free; end; If your version doesn't have it, there are plenty of 3rd party JSON libraries available. I am using Delphi 10.1 Update 2. Share this post Link to post
JIMSMITH 1 Posted Sunday at 10:28 PM 13 hours ago, Remy Lebeau said: What version of Delphi are you using? Delphi has had a built-in JSON framework for a long time, have you tried it yet? For example: uses ..., System.JSON; var JSON = '...'; var obj = TJSONObject.ParseJSONValue(JSON) as TJSONObject; try for var element in (obj.GetValue('MAILCONFIGS') as TJSONArray) do begin for var pair in (element as TJSONObject) do begin var email := pair.JsonString.Value; var config := pair.JsonValue as TJSONObject; var clientId := config.GetValue('client_id').Value; var appToken := config.GetValue('apptoken').Value; var tempToken := config.GetValue('temptoken').Value; ... end; end; finally obj.Free; end; If your version doesn't have it, there are plenty of 3rd party JSON libraries available. Remy, I am using Delphi 10.1 Update 2. I was able to figure it out from the code that you provided plus prior work. So I am good at this point and thanks for your help. 1 Share this post Link to post