I am trying to deserialize a JSON object with an objectlist, following the examples from the mormot forum does not work, can anyone help me:
Memo.Text := '{"CODIGO":"01","NOME":"CIDO","TELEFONES":[{"DDD":"18","NUMERO":"996237140"},{"DDD":"18","NUMERO":"996237140"}]}';
var
ClientesVO : TClientesVO;
TelefonesVO : TTelefonesVO;
isValid : boolean;
begin
Memo.Text := '{"CODIGO":"01","NOME":"CIDO","TELEFONES":[{"DDD":"18","NUMERO":"996237140"},{"DDD":"18","NUMERO":"996237140"}]}';
ClientesVO := TClientesVO.Create;
TelefonesVO := TTelefonesVO.Create;
TJSONSerializer.RegisterClassForJSON([TClientesVO,TTelefonesVO]);
JSONToObject(ClientesVO, @Memo.Text[1], isValid, nil, [j2oIgnoreUnknownProperty]);
ObjectToJson(TelefonesVO,ClientesVO.TELEFONES.Items[0]);
Classes:
type
TTelefonesVO = class(TSynPersistent)
private
P_DDD : RawUTF8;
P_NUMERO : RawUTF8;
published
property DDD : RawUTF8 read P_DDD write P_DDD;
property NUMERO : RawUTF8 read P_NUMERO write P_NUMERO;
end;
type TPhoneVOObjArray = Array of TTelefonesVO;
type
TClientesVO = class(TSynPersistent)
private
P_CODIGO : RawUTF8;
P_NOME : RawUTF8;
P_TELEFONES : TPhoneVOObjArray;
published
property CODIGO : RawUTF8 read P_CODIGO write P_CODIGO;
property NOME : RawUTF8 read P_NOME write P_NOME;
property TELEFONES : TPhoneVOObjArray read P_TELEFONES write P_TELEFONES;
end;