You are not logged in.
In method JSONToObject have the following code to treat the property with value = null.
if PInteger(result)^=NULL_LOW then begin
// nested null object
if (IsObj in [oSQLRecord,oSQLMany]) or (Kind<>tkClass) then
exit; // null expect a plain TObject
V := P^.GetOrdProp(Value);
if Obj<>nil then begin
// null -> FreeAndNil(Obj)
Obj.Free;
P^.SetOrdProp(Value,0);
end;
end else
when encountering a value = null, stop the deserialization.
I would like to finalize the deserialization. how do?
EX.:
if PInteger(result)^=NULL_LOW then begin
// nested null object
if (IsObj in [oSQLRecord,oSQLMany]) then
exit; // null expect a plain TObject
if (Kind=tkClass) then
begin
V := P^.GetOrdProp(Value);
if Obj<>nil then begin
// null -> FreeAndNil(Obj)
Obj.Free;
P^.SetOrdProp(Value,0);
end;
end;
for i:=1 to 5 do inc(From);
end else
Result with your code (property "valor" = 1000)
Result with your code (property "valor" = null)
Result with my code (property "valor" = null)
Offline
The json comes from a java service that allows string = null.
Even an object = null, generates this problem. the deserialization is aborted. (property "empresas1" type object)
I would like to finalize the deserialization in this case.
Offline
Hi, ab.
We have extract data from database where some fields comes null. When we try to use JSONtoObject the deserialization is aborted with properties with null value.
What can I do?
Thank's
This is then example data
TDTOTurRes = class(TCollectionItem)
private
fNombre: Variant;
fSexo, fEmail, fFax, fPasaporte, fTelefono, fIdSuperClasifEdad,
fNombClasifEdad, fNombIdioma, fserieticket, fNombSuperClasifEdad,
fNombCliente, fDireccion, fDireccion2, fCodigopostal, fVuelo_ret,
fCodigopostal2, fEstadoDir, fEstadoDir2, fCiudad, fCiudad2, fApellidos,
fApellidos2, fCodigo, fTelefono2: Variant;
fIdClasifEdad, fIdReserva,fIdDesglose,fIdTipoHabit, fIdPlan,fIdRecorrido,
fIDReservafuente, fIDResitemserv, fidcondpago, fpagada, fsecotiza, fTercero,
fEsCancelado, faction, fIdIdioma, fIdPais, fEdad, fIdTurista, fFree,
fIdCliente, fNumero, fTipo_doc_prm, fTipo_doc_sec, fEmisor_doc_prm,
fEmisor_doc_sec, fId_PaisResid, fIdClaseAerea{, fIdVueloReserva}: Variant;
fIdReservaPadre: double;
fIDTipoProducto, fIDEstadoReserva, fIDTipoServicio, fIdTipoPax, fNombre_seg,
fDocumento_sec{, fHabRecogida}: Variant;
fFecha_venc_prm, fFecha_venc_sec, fFecha_nac: Variant;
published
property Nombre: Variant read fNombre write fNombre;
property Sexo: Variant read fSexo write fSexo ;
property Email: Variant read fEmail write fEmail ;
property Fax: Variant read fFax write fFax ;
property Pasaporte: Variant read fPasaporte write fPasaporte ;
property Telefono: Variant read fTelefono write fTelefono ;
property IdSuperClasifEdad: Variant read fIdSuperClasifEdad write fIdSuperClasifEdad;
property NombSuperClasifEdad: Variant read fNombSuperClasifEdad write fNombSuperClasifEdad ;
property NombClasifEdad: Variant read fNombClasifEdad write fNombClasifEdad ;
property NombCliente: Variant read fNombCliente write fNombCliente ;
property NombIdioma: Variant read fNombIdioma write fNombIdioma ;
property IdClasifEdad: Variant read fIdClasifEdad write fIdClasifEdad ;
property IdReserva: Variant read fIdReserva write fIdReserva;
property IdIdioma: Variant read fIdIdioma write fIdIdioma;
property IdCliente: Variant read fIdCliente write fIdCliente;
property IdReservaPadre: double read fIdReservaPadre write fIdReservaPadre;
property IdPais: Variant read fIdPais write fIdPais;
property Edad: Variant read fEdad write fEdad;
property IdTurista: Variant read fIdTurista write fIdTurista;
property IdDesglose: Variant read fIdDesglose write fIdDesglose;
property IdTipoHabit: Variant read fIdTipoHabit write fIdTipoHabit;
property IdPlan: Variant read fIdPlan write fIdPlan;
property IdRecorrido: Variant read fIdRecorrido write fIdRecorrido;
property IDReservafuente: Variant read fIDReservafuente write fIDReservafuente;
property IDResitemserv: Variant read fIDResitemserv write fIDResitemserv;
property serieticket: Variant read fserieticket write fserieticket ;
property idcondpago: Variant read fidcondpago write fidcondpago;
property pagada: Variant read fpagada write fpagada ;
property secotiza: Variant read fsecotiza write fsecotiza ;
property Tercero: Variant read fTercero write fTercero;
property EsCancelado: Variant read fEsCancelado write fEsCancelado;
property action: Variant read faction write faction;
property Free: Variant read fFree write fFree ;
property IDTipoProducto: Variant read fIDTipoProducto write fIDTipoProducto;
property IDEstadoReserva: Variant read fIDEstadoReserva write fIDEstadoReserva;
property IDTipoServicio: Variant read fIDTipoServicio write fIDTipoServicio;
property IdTipoPax: Variant read fIdTipoPax write fIdTipoPax;
property Numero: Variant read fNumero write fNumero;
property Tipo_doc_prm: Variant read fTipo_doc_prm write fTipo_doc_prm;
property Tipo_doc_sec: Variant read fTipo_doc_sec write fTipo_doc_sec;
property Emisor_doc_prm: Variant read fEmisor_doc_prm write fEmisor_doc_prm;
property Emisor_doc_sec: Variant read fEmisor_doc_sec write fEmisor_doc_sec;
property Nombre_seg: Variant read fNombre_seg write fNombre_seg;
property Documento_sec: Variant read fDocumento_sec write fDocumento_sec;
property Fecha_venc_prm: Variant read fFecha_venc_prm write fFecha_venc_prm;
property Fecha_venc_sec: Variant read fFecha_venc_sec write fFecha_venc_sec;
property Fecha_nac: Variant read fFecha_nac write fFecha_nac;
property Direccion: Variant read fDireccion write fDireccion;
property Direccion2: Variant read fDireccion2 write fDireccion2;
property Codigopostal: Variant read fCodigopostal write fCodigopostal;
property Vuelo_ret: Variant read fVuelo_ret write fVuelo_ret;
property Codigopostal2: Variant read fCodigopostal2 write fCodigopostal2;
property EstadoDir: Variant read fEstadoDir write fEstadoDir;
property EstadoDir2: Variant read fEstadoDir2 write fEstadoDir2;
property Ciudad: Variant read fCiudad write fCiudad;
property Ciudad2: Variant read fCiudad2 write fCiudad2;
property Id_PaisResid: Variant read fId_PaisResid write fId_PaisResid;
property Apellidos: Variant read fApellidos write fApellidos;
property Apellidos2: Variant read fApellidos2 write fApellidos2;
property IdClaseAerea: Variant read fIdClaseAerea write fIdClaseAerea;
property Codigo: Variant read fCodigo write fCodigo;
property Telefono2: Variant read fTelefono2 write fTelefono2;
end;
TDTOTurResList = class(TInterfacedCollection)
private
function GetCollItem(aIndex: Integer): TDTOTurRes;
protected
class function GetClass: TCollectionItemClass; override;
public
function Add: TDTOTurRes;
property Item[aIndex: Integer]: TDTOTurRes read GetCollItem; default;
end;
implementation
{ TDTOTurResList }
function TDTOTurResList.Add: TDTOTurRes;
begin
result := TDTOTurRes(inherited Add);
end;
class function TDTOTurResList.GetClass: TCollectionItemClass;
begin
result := TDTOTurRes;
end;
function TDTOTurResList.GetCollItem(aIndex: Integer): TDTOTurRes;
begin
result := TDTOTurRes(GetItem(aIndex));
end;
TurServRes := TDTOTurResList.Create;
TurServResStr := '[{"IDTURISTA":53702,"NOMBRE":null,"IDIDIOMA":2,"IDRESERVAPADRE":33076,"IDSUPERCLASIFEDAD":"MAY","NOMBSUPERCLASIFEDAD":"MAYOR","IDPAIS":215,"EDAD":null,"EMAIL":null,"FAX":null,"PASAPORTE":null,"TELEFONO":null,"NOMBIDIOMA":"INGLES","SEXO":null,"IDRESERVA":null,"IDCLASIFEDAD":null,"NOMBCLASIFEDAD":null,"IDCLIENTE":281,"NOMBCLIENTE":"ABTOUR VIAJES","ACTION":1,"NUMERO":null,"CODIGOPOSTAL":null,"DIRECCION":null,"DIRECCION2":null,"DOCUMENTO_SEC":null,"EMISOR_DOC_PRM":null,"EMISOR_DOC_SEC":null,"FECHA_NAC":null,"FECHA_VENC_PRM":null,"FECHA_VENC_SEC":null,"NOMBRE_SEG":null,"TIPO_DOC_PRM":null,"TIPO_DOC_SEC":null,"VUELO_RET":null,"CODIGOPOSTAL2":null,"ESTADODIR":null,"ESTADODIR2":null,"CIUDAD":null,"CIUDAD2":null,"ID_PAISRESID":null,"APELLIDOS":null,"APELLIDOS2":null,"IDCLASEAEREA":null,"CODIGO":null,"TELEFONO2":null},{"IDTURISTA":53703,"NOMBRE":null,"IDIDIOMA":2,"IDRESERVAPADRE":33076,"IDSUPERCLASIFEDAD":"MAY","NOMBSUPERCLASIFEDAD":"MAYOR","IDPAIS":215,"EDAD":null,"EMAIL":null,"FAX":null,"PASAPORTE":null,"TELEFONO":null,"NOMBIDIOMA":"INGLES","SEXO":null,"IDRESERVA":null,"IDCLASIFEDAD":null,"NOMBCLASIFEDAD":null,"IDCLIENTE":281,"NOMBCLIENTE":"ABTOUR VIAJES","ACTION":1,"NUMERO":null,"CODIGOPOSTAL":null,"DIRECCION":null,"DIRECCION2":null,"DOCUMENTO_SEC":null,"EMISOR_DOC_PRM":null,"EMISOR_DOC_SEC":null,"FECHA_NAC":null,"FECHA_VENC_PRM":null,"FECHA_VENC_SEC":null,"NOMBRE_SEG":null,"TIPO_DOC_PRM":null,"TIPO_DOC_SEC":null,"VUELO_RET":null,"CODIGOPOSTAL2":null,"ESTADODIR":null,"ESTADODIR2":null,"CIUDAD":null,"CIUDAD2":null,"ID_PAISRESID":null,"APELLIDOS":null,"APELLIDOS2":null,"IDCLASEAEREA":null,"CODIGO":null,"TELEFONO2":null}]'
JSONToObject(TurServRes,pointer(TurServResStr),Valid,TDTOTurRes);
Offline
Should be fixed by http://synopse.info/fossil/info/6ee8821b32
Thanks for the report!
Offline
Hi ab, thank for your answer. But we don't work fine.
When debuging the source we detect in line inc(From,4); one problem, From is initialization with ', ' and cause error in parsing json string. If we subtitute that line with GetJSONFieldOrObjectOrArray(From,@wasString,@EndOfObject); work fine.
Thank's
Offline
Offline
Hi, ab.
It's work fine!!!!!!!
Thank's
Offline