My jQuery ajax sending data to a servlet and the data is in the form of JSON String. Its getting posted successfully but on the Servlet side I need to read these key-val pairs. I tried using JSONObject class but I am not able to get it.
Javascript
var all_urls = [{"url1":"This is aaaal 1"},{"url2":"This is bbbb2"},{"url3":"This is cccc3"}];
$.ajax({
type : 'POST',
dataType:'json',
data: { jsonData : JSON.stringify(all_urls ) },
url : 'GetUserServlet',
success : function(data) {
$('#addText').text(data);
},
error : function(xhr, textStatus, errorThrown) {
alert(xhr.responseText);
}
});
Servlet
String myJsonData = request.getParameter("jsonData");
This is what I am getting using request.getParameter("jsonData") on the request object:
[{"url1":"This is aaaal 1"},{"url2":"This is bbbb2"},{"url3":"This is cccc3"}, {}...]
Need to parse the above JSON value then need to add some token along with values and send back as response.
[{"url1":"This is aaaal 1 & a=abc"},{"url2":"This is bbbb2 & a=xyz"},{"url3":"This is cccc3 & a= ijk"},{}...]
Any help appreciated!