如何在JSP中访问JSONArray元素

我的JSONArray是

[

{"id":1,

"programs_idprograms":3,

"description":"course description",

"idCourse":"course title"

},

{"id":2,

"programs_idprograms":3,

"description":"course description2",

"idCourse":"course title2"

}

]

存储在名为bean2的字符串中

回答:

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");

}

以上是 如何在JSP中访问JSONArray元素 的全部内容, 来源链接: utcz.com/qa/427398.html

回到顶部