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

Inicio > Exportar JSon parcial a un mensaje de respuesta

Pregunta
Kurro Lopez · 25 feb, 2021

Exportar JSon parcial a un mensaje de respuesta

Hola a todos,

Tengo una operación de API que llama a un proceso externo. La respuesta es un gran json, pero solo quiero una parte del contenido completo.

Mi primer intento es:

 .....
// Se omite el código de preparación de la solicitud.
establecer tSC = ..Adapter.SendFormDataArray (.tHttpResponse, "POST", tHttpRequest ,,, tURL)
si $$$ ISERR (tSC) $$$ ThrowStatus (tSC)
// Obtén la respuesta directamente
establecer respuesta = ""
while (tHttpResponse.Data.AtEnd = 0) {
establecer respuesta = respuesta_tHttpResponse.Data.Read ()
}
// Convierta Json en un objeto genérico, obtenga el nodo returnValue.data y convierta a JSon nuevamente
set objJson = ## class (% DynamicObject).% FromJSON (respuesta)
establecer jsonReturnValue = objJson.returnValue.data.% ToJSON ()
$$$ TRACE ("Content ReturnValue:" _jsonReturnValue)
do ## class (% ZEN.Auxiliary.jsonProvider).% ConvertJSONToObject (jsonReturnValue, "MyMsg.PartialJson",. pResponse)
......

La respuesta de JSon es:

{
  "result": "OK",
  "returnValue": {
    "code": "0",
    "message": "Info",
    "data": {
      "ext_customer_id": "123456789",
      "customer_name": "FRANCISCO",
      "customer_surname_1": "LÓPEZ",
      "customer_surname_2": "DE LAS HERAS",
      "passport_id": "123456ZZZ",
      "dob": "1972-02-01",
      "sex": "M",
      "email": "kurro.lopez@gmail.com",
      "active": true
    }
  }
}

y la clase MyMsg.PartialJson es:

 Class MyMsg.PartialJson extiende Ens.Response
{
/// Id del usuario
Propiedad "ext_customer_id" como% String (MAXLEN = 1024);
/// Nombre del cliente
Propiedad "customer_name" como% String (MAXLEN = 1024);
/// Apellido cliente
Propiedad "customer_surname_1" como% String (MAXLEN = 1024);
/// apellido 2 cliente
Propiedad "customer_surname_2" como% String (MAXLEN = 1024);
/// Passport ID
Propiedad "passport_id" como% String (MAXLEN = 250);
/// Fecha de nacimiento
Propiedad dob As% String (MAXLEN = 20);
/// Sexo
Sexo de la propiedad como% String (MAXLEN = 10);
/// Correo electrónico
Correo electrónico de la propiedad como% String (MAXLEN = 1024);
/// Compruebe si el cliente está activo
Propiedad activa como% booleano;
}

Pero el objeto pResponse está vacío.

¿Hay algun error?

Atentamente
Kurro Lopez

#Caché

URL de fuente:https://es.community.intersystems.com/post/exportar-json-parcial-un-mensaje-de-respuesta