I want to send the json string to restful services using post method. It is being sent, but the data received at the server side has a different format. What have I missed?
This is my restful service in java
@Path("/CommonDemo")
public class CommonDemo
{
@POST
@Consumes(MediaType.APPLICATION_JSON)
public String result(String user)throws ServletException, IOException
{
System.out.println(user);
return user;
}
}
I am calling the above service using the jquery as follows.
var url = "http://localhost:8080/Snefocare/CommonDemo";
var user="{'serviceInfo': [{'name':'All'}]}";
$.ajax({
type: 'POST',
url: url,
contentType: "application/json; charset=utf-8",
data:{'user':user},
success: function(data, textStatus, jqXHR) {
alert('date'+data);
},
error: function(jqXHR, textStatus, errorThrown) {
alert('error: ' + textStatus +' ERROR:'+ errorThrown);
}
});
I am sending it with this statement
var user="{'serviceInfo': [{'name':'All'}]}";
and in the restful service, I am seeing it as
user=%7B'serviceInfo'%3A+%5B%7B'name'%3A'All'%7D%5D%7D
I do not know why the % and other digits have been added.