小编典典

如何在JSP中访问JSONArray元素

jsp

我的JSONArray是

[
   {"id":1,
    "programs_idprograms":3,
    "description":"course description",
    "idCourse":"course title"
   },
   {"id":2,
    "programs_idprograms":3,
    "description":"course description2",
    "idCourse":"course title2"
   }
]

存储在名为bean2的字符串中


阅读 837

收藏
2020-06-10

共1个答案

小编典典

JSONArray array = new JSONArray(bean2);
for(int i=0;i<array.length();i++){
    JSONObject object = array.getJSONObject(i);
    int id = object.getInt("id");
    int programs_idprograms = object.getInt("programs_idprograms");
    String description = object.getString("description");
    String idCourse = object.getString("idCourse");   
}
2020-06-10