I want to show the results of a Json response on a Visualforce page. At this moment im able to deserialize and show the results, but when I try to show the result of the Class in the visual force it shows the following error:
For testing i want to show in the VF page "Razon Social" of the class Empresa.
This is the class:
public class EquifaxEmpresa {
public List<Empresa> Empresa;
public class Empresa{
public String RazonSocial;
public String NombreComercial;
public String TipoContribuyente;
public String EstadoContribuyente;
public String CondicionContribuyente;
public String Dependencia;
public String CodigoCIIU;
public String DescripcionCIIU;
public String InicioActividades;
public String ActividadComercioExterior;
public String NumeroTrabajadores;
public String Direccion;
}
public static EquifaxEmpresa parse(String json){
return (EquifaxEmpresa) System.JSON.deserialize(json, EquifaxEmpresa.class);
}}
This is the controller class:
global class equifaxController {
public String idConsulta {get;set;}
public EquifaxEmpresa theEmpresa {get;set;}
public String mensaje {get;set;}
public void consultaPersona(){
string msj = '{'+
'"NroDocumento":"'+idConsulta+'",'+
'"Consulta":"Empresa"'+
'}';
Http http = new Http();
HttpRequest req = new HttpRequest();
req.setEndpoint('endpoint here');
req.setBody(msj);
req.setMethod('POST');
req.setHeader('Content-Type','application/json');
req.setTimeout(12000);
HttpResponse res = new HttpResponse();
//EquifaxEmpresa empresita = (EquifaxEmpresa)JSON.deserialize(msj, EquifaxEmpresa.class);
res = Http.send(req);
String temp = res.toString();
if(temp.contains('Error')){
system.debug('Error: '+res.getStatusCode());
}else{
String body = res.getBody();
theEmpresa = EquifaxEmpresa.parse(body);
system.debug(theEmpresa.Empresa[0].RazonSocial);
mensaje = body;
}
}
}
The visualforce page:
<apex:page controller="equifaxController">
<apex:pageBlock title="Datos de Empresa">
<apex:form >
<apex:inputText value="{!idConsulta }"/>
<apex:commandButton value="Consultar" action="{!consultaPersona}" reRender="dynamic"/>
</apex:form>
</apex:pageBlock>
<apex:outputPanel id="dynamic">
{!theEmpresa.Empresa[0].RazonSocial}
</apex:outputPanel>
</apex:page>
The other thing that I cannot understand, its why system.debug shows me {!theEmpresa.Empresa[0].RazonSocial} and VF not:
Thanks in advance
public List<Empresa> Empresa {get;set}
should solve the issue.