This is my code:
json = JSON.stringify(jsonObj);
$.ajax({
type: 'post',
url: 'PostStudentMarks',
async: false,
data: json,
contentType: "application/json",
dataType: 'json',
success: function (response) {
alert("Marks Uploaded");
},
error: function(err) {
console.log(arguments);
}
});
jsonObj
contains data like this
[{
"student_id": "11204172"
},{
"course_id": "PHY101",
"semester": "1",
"marks": "11"
},{
"course_id": "CSE401",
"semester": "2",
"marks": "22"
}]
What should be the proper Java code in the servlet to read and iterate through it?Currently I am using org.json.simple
. Moreover if I do like
JSONObject jsonObject = new JSONObject(request.getParameter("json"));
JSONArray json = new JSONArray(jsonObject);
It throws an error saying undefined constructor
. What is the proper solution for this? Also note that I do not want to use gson.