5
I am trying to deserialize a JSON Object with an objectlist, following the example of the forum mormot does not work, someone can 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;
I did some tests, and it worked out nice here for me. But mORMot seems to have some secrets as to the class statement. I could post the declaration code of your classes (Vos)?
– Victor Tadashi
I’m using Syncrossplatformjson to deserialize
– Aparecido Silva
Look, I’ve put together an example, and it works almost perfectly. I’m just not being able to deserialize the Colletctionitems from my JSON. What I noticed about mORMot, is that, they have some peculiarities in the creations of the classes. For example, classes with objects need to be inherited from the Collection and Collectionitem type. I had never messed with the serial version of mORMot (I use it only for REST client/server applications and as a tool for ORM). What is the exact problem you are having ?
– Victor Tadashi
I just looked at your class, and you’re not using the guys recommended by mORMot. I’ll answer with the example I have to see if it helps you a little
– Victor Tadashi
Cool, and thank you the I also use the Rest have an application with Delphi and Extjs 6.01 from everything works perfect. What I want is to deserialize Collectionitem, and I can’t
– Aparecido Silva
hoje o collectionItem eu uso uma variavel RawUTF8 pra mandar os itens o ExtJs entende, se uso no TClientesVO property TELEFONES : TList read P_TELEFONES write P_TELEFONES; no ObjectToJSON funciona perfeito, agora o problema é no JSONToObject ele dá erro
– Aparecido Silva