循环遍历类的所有成员
在顶点中,如果我想循环“内部”类的所有成员&根据它创建一个映射(成员名称到其值)。 我该怎么做?
提前致谢。
public class fromJSON{
公共布尔成功; 公共整数时间戳; //1646140623 公共字符串基础; //欧元 公共字符串日期J; //2022-03-01 公共地图<字符串,十进制>费率; 公共 cls_rates 费率;
class cls_rates {
public Double AED;
public Double AFN;
public Double ALL;
public Double AMD;
public Double ANG;
public Double AOA;
public Double ARS;
public Double AUD;
public Double AWG;
public Double AZN;
public Double BAM;
public Double BBD;
public Double BDT;
public Double BGN;
public Double BHD;
public Double BIF;
public Double BMD;
public Double BND;
public Double BOB;
public Double BRL;
public Double BSD;
public Double BTC;
public Double BTN;
public Double BWP;
public Double BYN;
public Double BYR;
public Double BZD;
public Double CAD;
public Double CDF;
public Double CHF;
public Double CLF;
}
}
In apex, if I want to loop over all members of a "inner" class & create a map from it (member name to its value).
How do I do that?
Thanks in advance.
public class fromJSON{
public boolean success;
public Integer timestamp; //1646140623
public String base; //EUR
public String dateJ; //2022-03-01
public Map<String, Decimal> rates;
public cls_rates rates;
class cls_rates {
public Double AED;
public Double AFN;
public Double ALL;
public Double AMD;
public Double ANG;
public Double AOA;
public Double ARS;
public Double AUD;
public Double AWG;
public Double AZN;
public Double BAM;
public Double BBD;
public Double BDT;
public Double BGN;
public Double BHD;
public Double BIF;
public Double BMD;
public Double BND;
public Double BOB;
public Double BRL;
public Double BSD;
public Double BTC;
public Double BTN;
public Double BWP;
public Double BYN;
public Double BYR;
public Double BZD;
public Double CAD;
public Double CDF;
public Double CHF;
public Double CLF;
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我们可能需要序列化内部类对象,并且需要使用deserializeUntyped方法将其反序列化,以将内部类成员变量保存到映射中。
We may need to serialize the inner class object and we would need to deserialize it using deserializeUntyped method for holding the inner class members variables into a map.