JSON in Delphi 7

Please discuss general Delphi programming topics here.

JSON in Delphi 7

Postby danielHP » January 29th, 2010, 5:53 am

Im using Delphi 7 and want to get JSON data from a memo object.
Its kinda look like this in the memo
the real data is more complex and hectic than above.
I want to separate each member into separate column in a table. Namely column id, curr_id, name,etc.
The JSON.org has pointed me to 3 different component
* Delphi Web Utils.
* JSON Delphi Library.(lkJSON)
* JSON Toolkit.(superobject v1.2.3)
and each one of them lacked (easy) documentation.
If anyone have already attempt to do something similar or know how to use the component, please help me.
Thank you.
Posts: 3
Joined: May 29th, 2009, 5:18 am

Re: JSON in Delphi 7

Postby Kambiz » January 30th, 2010, 3:54 pm

I looked at those libraries. As you said they suffer from a lack of documentation.

JSON Toolkit.(superobject v1.2.3) seems to be the well designed one but I couldn't find out how to use it.
Delphi Web Utils is my next choice according to the way it has been coded, but no way to find how to use it.
JSON Delphi Library (lkJSON) is messy a bit but if you look at its sample2.dpr, it'll somehow help you to understand its usage.
User avatar
Posts: 2430
Joined: March 7th, 2003, 7:10 pm

Re: JSON in Delphi 7

Postby surfzone » March 16th, 2010, 4:42 pm

JSON Delphi Library (lkJSON)

Example of use:

I get this JSON string:

{"Geocod": [{"acuracy": 90.12, "Addr": {"dir": "Carrer Major,10", "cp": "08551", "pob": "Tona", "prov": "Barcelona", "pais": "Spain" },"Coor": { "lat": 2.233180, "lng": 41.853790 }}, {"acuracy": 80.21, "Addr": {"dir": "Carrer Major, 30", "cp": "08551", "pob": "Tona", "prov": "Barcelona", "pais": "Spain" },"Coor": { "lat": 2.333180, "lng": 41.253790 }}]}

This is on Memo2.Lines;

Delphi example code:

procedure TForm1.Button7Click(Sender: TObject);
js: TlkJSONobject;
ja: TlkJSONlist;
i: integer;
s: string;

js := TlkJSON.ParseText(Memo2.Text) as TlkJSONobject;

ja := js.Field['Geocod'] as TlkJSONlist;

Memo3.Lines.Add(Format('Registers: %d', [ja.Count]));

for i := 0 to ja.Count - 1 do
s := VarToStr(ja.Child[i].Field['acuracy'].Value) + ' - ' +
VarToStr(ja.Child[i].Field['Addr'].Field['dir'].Value) + ' - ' +
FormatFloat('0.0000', ja.Child[i].Field['Coor'].Field['lat'].Value) + ' - ' +
FormatFloat('0.0000', ja.Child[i].Field['Coor'].Field['lng'].Value);
Posts: 1
Joined: March 16th, 2010, 3:48 pm

Return to Delphi Programming

Who is online

Users browsing this forum: No registered users and 2 guests