下面ismy代码是工作良好唯一的问题在最后一个循环我想改变小事我怎么知道是最后一个循环?我的代码不满足这个条件,如果(我== school5.length() - 1)在forloop结束,而不是替换,。我会doplease帮我我的条件不满意forloop结束请帮我请
JSONArray school5 = json2.getJSONArray("dish_ingredient");
String concatProduct = "";
for (int i = 0; i < school5.length(); i++) {
String name = school5.getJSONObject(i).getString("name");
String subIngredient = school5.getJSONObject(i).getString("sub_ingredients");
if(i == 0){
if (subIngredient.equals(""))
{
if(i == school5.length()-1)
{
concatProduct = " " + "<b>" + name + "</b>"+". " + subIngredient;
}
else
{
concatProduct = " " + "<b>" + name + "</b>"+", " + subIngredient;
}
}
else
{
concatProduct = " " + "<b>" + name + "</b>"+": " + subIngredient;
}
} else {
if (subIngredient.equals(""))
{
concatProduct += " " + "<b>" + name + "</b>"+", " + subIngredient;
}
else
{
concatProduct += " " + "<b>" + name + "</b>"+": " + subIngredient;
}
}
}
你应该格式化你的代码,以便其他人可以正确读取它 – Shubhank