我在另一个for循环中使用一个for循环,问题是我需要Left选项,Right选项和答案,但仅获取每个选项的最后一项。我将如何获得?请帮帮我
for (int i = 0; i < jsonArray.length(); i++) {
DataModel model = new DataModel();
jsonObject = jsonArray.getJSONObject(i);
LeftOpts = jsonObject.getString("LQUESTION");
RightOpts = jsonObject.getString("RQUESTION");
Ans = jsonObject.getString("TRUE_ANS");
String[] leftItem = LeftOpts.split("@");
String[] rightItem = RightOpts.split("@");
String[] ansItem = Ans.split("@");
for (int j = 0; j < leftItem.length; j++) {
item1 = leftItem[j];
Log.v("Left", item1);
model.setLOpt1(item1);
item2 = rightItem[j];
model.setROpt1(item2);
item3 = ansItem[j];
model.setAns1(item3);
myList.add(model);
}
答案 0 :(得分:1)
您可以尝试以下方法:
for (int j = 0; j < leftItem.length; j++) {
DataModel model = new DataModel(); //move to here
item1 = leftItem[j];
Log.v("Left", item1);
model.setLOpt1(item1);
item2 = rightItem[j];
model.setROpt1(item2);
item3 = ansItem[j];
model.setAns1(item3);
myList.add(model);
}