I need to generate a JSON file with Delphi 7. I use the LKJSON library.
I even managed to generate the file, but it was not the way I would need it.
Below the code I used to generate JSON:
procedure TForm1.Button3Click(Sender: TObject);
var
js: TlkJSONobject;
s: string;
i : Integer;
begin
SQLConnection1.Open;
taUF.Open;
js := TlkJSONobject.Create;
try
js.Add('estado', TlkJSONobject.Create);
taUF.First;
while not taUF.Eof do begin
with TlkJSONobject(TlkJSONobject(js['estado'])) do begin
Add('sigla', taUF.FieldByName('UFSigla').AsString);
Add('nome', taUF.FieldByName('UFNome').AsString);
end;
taUF.Next;
end;//while
i := 0;
s := GenerateReadableText(js, i);
Clipboard.SetTextBuf(PChar(s));
finally
js.Free;
end;
end;
This is the result:
{
"estado":{
"sigla":"RJ",
"nome":"RIO DE JANEIRO",
"sigla":"SC",
"nome":"SANTA CATARINA"
}
}
I need it to look this way:
{
"estado":
{
"sigla":"RJ",
"nome":"RIO DE JANEIRO"
},
{"sigla":"SC",
"nome":"SANTA CATARINA"
}
}