I'm trying to parse the json string into meaningful data over a VF page.
Here's where I'm stuck...
public class callApi{
private final String serviceEndpoint= 'http://XXX';
public String Response { get; set;}
public String Headers { get; set; }
public Boolean cache;
public List<Data> data { get; set; }
public Provider provider;
public class Data {
public String unique_id {get;set;}
public String description {get;set;}
public String title {get;set;}
}
public class Provider {
public String pubDate;
public String source;
public String url;
}
public void fetchmyData() {
getAndParse('GET');
}
public void getAndParse(String GET) {
Http http = new Http();
HttpRequest request = new HttpRequest();
String authorizationHeader = 'BASIC';
request.setEndpoint(serviceEndpoint);
request.setMethod('GET');
request.setHeader('Accept','text/html');
request.setHeader('Authorization', authorizationHeader);
request.setTimeout(120000);
HttpResponse json= http.send(request);
System.debug(json.getBody());
this.response=json.getBody();
callApi temp = parse(this.response);
System.debug('@@temp'+temp);
List<Data> dr = new List<Data>();
for(Data d : temp){
unique_id = d.unique_id;
description = d.description;
unique_id = d.unique_id;
dr.add(d);
}
}
public static callApi parse(String json) {
System.debug('@@json'+json);
return (callApi) System.JSON.deserialize(json, callApi.class);
}
}
And here's the VF page
<apex:page controller="callApi">
<apex:form >
<apex:pageBlock title="Get News">
<apex:pageBlockButtons title="News">
<apex:commandButton value="Get News" action="{!fetchmyData}" reRender="myBlock" />
</apex:pageBlockButtons>
<apex:pageBlockSection id="myBlock" columns="1">
<apex:repeat value="{!dr}" var="line">
<apex:outputText value="{!line.title}" id="theValue"/>
</apex:repeat>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
</apex:page>
I get the a proper response string in temp. But I'm unable to parse and format the values. I do get a proper string if I put the repeat values as "!response", but this is not what I need. I require the data inside such as unique_id, description and title. I get the following error:
Error: Compile Error: Variable does not exist: unique_id at line 49
I'm new to REST API, a help would be much appreciated! Thanks in advance.