在此处输入图像描述我有一个名为价格的字符串。我从 firebase 数据库中获取 Price 的值。我想将这些字符串值相加并得出总价。价格值根据数据库中的子项自动增加。例如,值为 100、70、50、20、40 等。它会相应地增加。
我认为应该有一个循环来使所有这些值的总和成为总价。
这就是我到目前为止所做的。
int pos = 0;
JSONObject jsonObject = new JSONObject();
if (jsonObject.has(Integer.toString(pos))) {
} else {
try {
jsonObject.put(Integer.toString(pos),Price);
} catch (JSONException e) {
e.printStackTrace();
}
}
for (int i = 0; i < jsonObj.length(); i++) {
try {
String itemInArray = jsonObj.getString(String.valueOf(i));
int Sum = 0;
int totalPrice = sum + itemInArray;
} catch (JSONException e) {
e.printStackTrace();
}
}
但是代码不起作用。请提供任何帮助,我们将不胜感激。
冉冉说
相关分类