Background:
I have an application in VB.NET where I consume some web services "API's". One of these API (for purposes of the question it will be called EnviarArchivo
) returns an object with this structure:
API response EnviarArchivo
:
[{
"DocumentType": "SalesInvoice",
"CreationDate": "2019-01-02T15:26:00.041Z",
"DocumentDate": "2018-10-17T00:00:00",
"DueDate": "2018-10-17T00:00:00.000Z",
"Currency": "COP",
"BusinessStatus": "Certified",
"CommunicationStatus": "DeliverOk",
"MainNotificationEmailStatus": "Delivered",
...
}]
I have a global variable called "translationResponsesAPI" whose value is a JSON object with this structure:
global variable traduccionRespuestasAPI
:
var traduccionRespuestasAPI = {
"Cancel": "Cancelar",
"Categories": "Categorias",
"Certified": "Certificado",
"CitizenshipCard": "Tarjeta Ciudadanía",
"Delireved": "Entregado",
"Delivered": "Entregado",
"DeliverOk": "Entrega Exitosa",
"Description_Label": "Descripción",
"Received": "Recibido",
"Registered": "Registrado",
"Reject": "Rechazar",
...
};
Problem:
What I'm looking for is that "according to the API response EnviarArchivo
" query the global variable traduccionRespuestasAPI
and set the value.
Example:
If the API response EnviarArchivo
in the "BusinessStatus" field was "Certified", it should look in the global variable for traduccionRespuestasAPI
the attribute named "Certified" and return the value "Certificate".
Without using loops, how to access local variable value based on API response?
Assuming that the value of the API response is always going to be present in your translations object, you can do it like this: