Your question seems odd to me, if you want to retrieve user input fields from a visualforce page, first you need to know what are the fields you need from it and then you can call those values from your apex methods, for example:
//this is the default value for this parameter
private String empresa = 'Global';
//this defines how to call the value
public String getEmpresa() {
return empresa;
}
//setter method
public void setEmpresa(String empresa) { this.empresa = empresa; }
//in the visualforce
<td align="center" valign="top">
<label><b>Empresa</b></label>
</td>
<apex:actionRegion >
<td align="left" valign="middle">
<apex:selectList value="{!Empresa}" multiselect="false" size="1">
<apex:selectOptions value="{!items}"/>
<apex:actionSupport event="onchange" rerender="paquetes,paquetesDetalle" status="cargando"/>
</apex:selectList><p/>
</td>
</apex:actionRegion>
Of course there are other ways to get it done, but if this is not your case be more specific about what you need
Regards
The method JSON.deserializeUntyped works well for this type of problem. What you get returned is a map:
Map<String, Object> m = (Map<String, Object>) JSON.deserializeUntyped(jsonString);
You can use the normal map methods to get hold of the keys or to see if a key is present. So for example to access the "ideal" list items:
List<Object> ideals = (List<Object>) m.get('ideal');
if (ideals != null) {
for (Object ideal : ideals) {
String product = (String) ideal('product');
String percent = (String) ideal('percent');
String dollarAmount = (String) ideal('dollarAmount');
...
}
}
Because it is known that the data is a list (array) I've just cast the object to a list. If the content is of very unpredictable type you can also use instanceof
tests in your logic.
Here is your JSON having been formatter by http://jsonformatter.curiousconcept.com/; this sort of formatting makes the JSON easier to understand:
{
"ideal":[
{
"product":"4",
"percent":"25",
"dollarAmount":"11250"
},
{
"product":"5",
"percent":"23",
"dollarAmount":"10350"
},
{
"product":"3",
"percent":"20",
"dollarAmount":"9000"
},
{
"product":"8",
"percent":"18",
"dollarAmount":"8100"
},
{
"product":"7",
"percent":"15",
"dollarAmount":"6750"
}
],
"idealFiltered":[
{
"product":"4",
"percent":"25",
"dollarAmount":"11250"
},
{
"product":"5",
"percent":"23",
"dollarAmount":"10350"
},
{
"product":"3",
"percent":"20",
"dollarAmount":"9000"
},
{
"product":"8",
"percent":"18",
"dollarAmount":"8100"
},
{
"product":"7",
"percent":"15",
"dollarAmount":"6750"
}
],
"InBudget":[
{
"product":"4",
"percent":"70",
"dollarAmount":"7000"
},
{
"product":"8",
"percent":"30",
"dollarAmount":"3000"
}
]
}
Best Answer
Take a look at
JSON.deserialize();
(documentation)In your case, what you will have to do is create 2 inner classes like so:
then deserialize your JSON string in a new instace of the classes you created.
now you'll be able to programatically approach the values of your json string in the new list.