I'm trying to handle a JSON response..the format it comes in is not the best but I can't change it..Ive used JSON2APEX and can access the object values individually but I need to loop through them
The JSON2APEX class goes like this
public class DataSource {
public Data _PLU;
public Data _1ST;
public Data _VSL;
public Data _ARC;
public Data _ICN;
public Data _REP;
public Data _SNGLS;
public Data _XAUR;
public Data _DGD;
public class Data {
public String percentChange;
public String baseVolume;
public String quoteVolume;
}
public static DataSource parse(String json) {
return (DataSource) System.JSON.deserialize(json,DataSource.class);
}
}
so instead of this "DataSource._PLU.baseVolume" I want to do something like
for(DataSource o : Data){
string s = o.baseVolume;
}
Any ideas?
ps I've tried Map<string, Object> meta = (Map<string, Object>) JSON.deserializeUntyped(data);
but when I try to loop through the keyset I can get the values but not drill down to each attribute
ex.
for(String obj : meta.keyset()){
system.debug("sample"+meta.get(obj).baseVolume;
}
I get a variable doesn't exist error for baseVolume