Deserializing a Response

Hi.
I need to deserialize a response.
The scenario is...
I have the class below:

TEndereco = class
public
cep: String;
logradouro: String;
compelmento: String;
bairro: String;
localidade:String;
uf: string;
ibge: string;
gia: string;
ddd: string;
siafi: string;

end;

TListaEndereco = class
private
FEnderecos: TList;
public
property Enderecos: TList read FEnderecos Write FEnderecos;
end;

When a I consume the ws, the answer in JSON is like example below:
[
{
"cep": "13400-060",
"logradouro": "Rua Governador Pedro de Toledo",
"complemento": "até 1070 - lado par",
"bairro": "Centro",
"localidade": "Piracicaba",
"uf": "SP",
"ibge": "3538709",
"gia": "5356",
"ddd": "19",
"siafi": "6875"
},
{
"cep": "13400-075",
"logradouro": "Rua Governador Pedro de Toledo",
"complemento": "de 1283 ao fim - lado ímpar",
"bairro": "Centro",
"localidade": "Piracicaba",
"uf": "SP",
"ibge": "3538709",
"gia": "5356",
"ddd": "19",
"siafi": "6875"
}
]

Well, how can I to deserialize this json to my list of objects?
I´m using the command:
FListaEndereco := TListaEndereco.Create;
FListaEndereco.Enderecos :=
TJson.Deserialize'<'TEndereco'>'(ResponseBody);

Off course, not works !!!
Thanks for attention.

Hi there,

uses
  Generics.Collections;

(* *)

var
  Lista: TList<TEndereco>;
begin
  Lista := TJson.Deserialize<TList<TEndereco>>(ResponseBody);

That should work.
Regards,

1 Like

Yes, worked fine!
I uses TObjectList rather than TList.
I think there is no problem, right ?
Thanks again.
Regards

1 Like

You can deserialize is as TObjectList as well.