【发布时间】:2020-03-05 18:27:40
【问题描述】:
我编写了一段代码,用于从表中获取值并将其放置在带有键值对的映射中并返回映射。
public Map<String, BigDecimal> fnFetchCartSummary() throws Exception {
Map<String, BigDecimal> mCartSummaryMap = new HashedMap<String, BigDecimal>();
int iCartCount = client.getElementCount(CartTotal);
if (iCartCount > 1) {
client.ValidateTest(true, "Service charges are getting displayed for Cart. Total entries = " + iCartCount);
for (int i = 1; i <= iCartCount; i++) {
String sVariablexpath = sRowKey.replaceAll("<REPLACE>", Integer.toString(i));
String sVariableName = client.getText(sVariablexpath).replace(":", "");
String sCharges = RowValue.replaceAll("<REPLACE>", Integer.toString(i));
double sPrice =Double.parseDouble( client.getText(sCharges).replaceAll("[^0-9.]+", ""));
BigDecimal bdPrice = new BigDecimal(sPrice);
mCartSummaryMap.put(sVariableName, bdPrice);
}
}
return mCartSummaryMap;
}
这将返回具有类似值的地图
{MPVPERTKTF=10, Subtotal=1200, MPVEVTF=15, Total Amount Due=1227, MPV SC001 SPD=2}
但是当我试图捕捉同一张地图并试图从中获取价值时。
Map<String, BigDecimal> mCartValue1 = client.shoppingCart.fnFetchCartSummary();
BigDecimal Subtotal1_1 = mCartValue1.get("Subtotal");
System.out.println(Subtotal1_1);
它会像这样对每个键值对显示 null
空
如果有人遇到同样的问题,请给我建议一个解决方案。????
【问题讨论】:
-
不可能。我确定你在做其他事情。
-
因为我已经为特定工具编写了这段代码。作为java的角度,你能详细说明这里的问题吗?
-
您可以使用调试器检查地图
mCartValue1包含哪些元素吗? (或者干脆打印出来) -
看起来您正在从某个外部资源(可能是 DOM 或类似的东西)获取地图的字符串值。显示为“小计”的字符串很可能包含该版本中的一些不可见字符。打印出每个键的长度并对照文本进行目视检查,以验证其中不包含不可见字符。
-
你能不能在
BigDecimal Subtotal1_1 = mCartValue1.get("Subtotal");前面的那一行做System.out.println(mCartValue1);并将它添加到你的帖子中