Read JSON with Delphi 6

Asked

Viewed 799 times

4

I have a JSON file, but I would like to read it using Delphi 6. It would be possible?

Follow an example from JSON

{
   "size":1,
   "response":[
      {
         "id_cliente":21,
         "nome":"DESENTUPIDORA ME",
         "endereco":"RUA J, Nº. 9",
         "complemento":"TÉRREO ",
         "bairro":"SANTOS",
         "cidade":"VITÓRIA",
         "estado":"ES",
         "cep":"29.000-000",
         "telefone":"28-18987677",
         "telefone_fax":"28-9878-08685",
         "email":"[email protected]",
         "cnpj":"098873.835/0033-87",
         "pesagem_livre":0,
         "nome_fantasia":"DESENTUPIDORA SJOE -ME",
         "tipo_cliente":"privado",
         "inscricao_estadual":"",
         "situacao":true,
         "inscricao_municipal":"",
         "periodo_medicao":"9931",
         "anotacoes":"",
         "data_inclusao":null
      }
   ]
}
  • Daniel, I can’t formulate an answer for lack of time, but research on Superobject for Delphi6, is a library that you can do whatever you want ;)

1 answer

2

You can use the json4delphi, that has the routines for Delphi 6 or higher. In the Github link there is an example of use, but I will replicate it here:

var
  Json: TJson;
  Str: String
begin
  Json := TJson.Create();

  //put
  Json.Put('field1', null);
  Json.Put('field2', True);
  Json.Put('field3', 3.14);
  Json.Put('field4', 'hello world');

  //another way
  Json['field5'].AsBoolean := False;
  Json['field6'].AsString := 'hello world';

  //object
  with Json['field7'].AsObject do
  begin
    Put('subfield1', 2.7182818284);
    Put('subfield2', 'json4delphi');
  end;

  //array
  with Json['field8'].AsArray do
  begin
    Put(6.6260755e-34);
    Put('The magic words are squeamish ossifrage');
  end;

  //get
  Str := Json['field4'].AsString;

  //parse
  Json.Parse('{"a":1}');

  //stringify
  Str := Json.Stringify;
end;
  • 1

    Thank you so much for your attention I’ll try to use.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.