public class test5 {
public list<string> lststatename{get;set;}
public list<string> lstrating{get;set;}
public test5(){
string jsonexample1 = ' { "overalldata": [ {"stateName": "Andrapradesh", "rating": 5.0 }, { "stateName": "Telangana", "rating": 4.0 }, {"stateName": "Banglore", "rating": 5.0 } , {"stateName": "Maharastra", "rating": 4.5 } ] } ';
map<string,object> metadatamap= (map<string,object>)json.deserializeuntyped(jsonexample1);
list<object> values1= (list<object>)metadatamap.get('overalldata');
lststatename= new list<string>();
lstrating= new list<string>();
for(object parsed : values1){
map<string,object> values = (map<string,object>)parsed;
string statename = string.valueof(values.get('stateName'));
string rating= string.valueof(values.get('rating'));
lststatename.add(statename );
lstrating.add(rating);
}
}
}
visualforce page:
hi , im getting the data in the visualforce page , but the data is getting iterable when i use the repeat functionality inside the table , can anybody have the solution for this ??it should not iterate again .. thanks in advance<apex:page controller="test5" >
<apex:form >
<table>
<tr>
<th>states</th>
<th>rating</th>
</tr>
<apex:repeat value="{!lststatename}" var="a">
<apex:repeat value="{!lstrating}" var="b">
<tr>
<td>{!a}</td>
<td>{!b}</td>
</tr>
</apex:repeat>
</apex:repeat>
</table>
</apex:form>
</apex:page>
Hi Deepika, One more update needs to be done. Please refer the below final updated code:
Also, find the attached image of the class in my org.Hope this will solve your problem. If does then mark it as the best answer so it can also help others in the future.Many Thanks,Sunil Rathorepublic class test5 {
public List<Overalldata> overalldata{get;set;}
public test5(){
string jsonexample1 = ' { "overalldata": [ {"stateName": "Andrapradesh", "rating": 5.0 }, { "stateName": "Telangana", "rating": 4.0 }, {"stateName": "Banglore", "rating": 5.0 } , {"stateName": "Maharastra", "rating": 4.5 } ] } ';
overalldata = (List<Overalldata>)json.deserializeuntyped(jsonexample1);
}
//Wrapper class
public class Overalldata {
public String stateName;
public Double rating;
}
}