You need to sign in to do that
Don't have an account?
Deepikareddy
here to use the html table to display the values, but the data is getting iterated again , Any body have any idea to handle this. thanks in advance ..
using the apex:repeat functionality in salesforce
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); } } }
<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>
here to use the html table to display the values, but the data is getting iterated again , Any body have any idea to handle this. thanks in advance ..
vf page replace table with below code
<table>
<tr>
<th>states</th>
<th>rating</th>
</tr>
<apex:repeat value="{!yourMap}" var="key">
<tr>
<td>{!key}</td><!-- key --->
<td>{!yourMap[key]}</td> <!-- Value--->
</tr>
</apex:repeat>
</table>
and APEX CLASS , i added "yourMap" in apex
public class test5 {
public map<string,string> yourMap {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');
yourMap = new MAP<String,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'));
yourMap.put(statename, rating);
}
}
}
All Answers
Problem is you added repeat inside repeat in page. Please fix that one
public list<string> lststatename{get;set;}
public list<string> lstrating{get;set;}
ypu can use simple map( MAP<String,decimal>) to store the values and display it
thank u
vf page replace table with below code
<table>
<tr>
<th>states</th>
<th>rating</th>
</tr>
<apex:repeat value="{!yourMap}" var="key">
<tr>
<td>{!key}</td><!-- key --->
<td>{!yourMap[key]}</td> <!-- Value--->
</tr>
</apex:repeat>
</table>
and APEX CLASS , i added "yourMap" in apex
public class test5 {
public map<string,string> yourMap {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');
yourMap = new MAP<String,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'));
yourMap.put(statename, rating);
}
}
}