Published on InterSystems Developer Community (https://community.intersystems.com)

Home > How to copy array values from JSon to object using DTL?

Question
Kurro Lopez · May 24, 2019

How to copy array values from JSon to object using DTL?

Hi community,

I need to create a DTL to get values from a JSon (%DynamicObject) to a class.

Thre first items is copied fine, however when it tries to get the values from an array it raises an error.

 

{
  "resultado": "OK",
  "retorno": {
    "mensaje": "Info recuperado correctamente",
    "datos": {
      "idUsuario": "ID-88556",
      "fechanacimiento": "1970-02-01",
      "nombreUsuario": "FRANCISCO",
      "apellidosUsuario": "LOPEZ",
      "polizas": {
        "poliza": [
          {
            "sucursal": "MAD",
            "oficina": "01",
            "poliza": "12345678",
          },
          {
            "sucursal": "BCN",
            "oficina": "34",
            "poliza": "99556151",
          }
        ]
      }
    }
  }
}

When the DTL gets the "poliza" array, it throws the following error.

ERROR <Ens>ErrException: <INVALID OREF>zTransform+16^MyApp.DT.JsonToPoliciesResponse.1 -- - registrado como '-' número - @' Set k1=source.retorno.datos.polizas.poliza.Next(k1)' 

is there any way to create a "loop", "for each" or whatever to iterate into?

 

Best regard,

Francisco Lopez

#DTL #Ensemble

Source URL:https://community.intersystems.com/post/how-copy-array-values-json-object-using-dtl