Possible Duplicate:
How to send a JSON object over Request with Android?
As I am new to Android development, I struck up with a problem sending requests to a web service in the form of JSON. Googling, I found the following code for sending requests using parameters. Here is the Java class we are sending parameters in the form of:
Main.java
RestClient client = new RestClient(LOGIN_URL);
client.AddParam("Email", _username);
client.AddParam("Passwd", _password);
try {
client.Execute(RequestMethod.POST);
} catch (Exception e) {
e.printStackTrace();
}
String response = client.getResponse();
But here I want to send parameters in the form of JSON, like for example I want to send parameters in this form:
{
"login":{
"Email":_username,
"Passwd":_password,
}
}
So, can anyone help me? How can I send parameters in the form of JSON?
The example you are posting uses a ‘library’ put together by someone as a wrapper around Apache’s HttpClient class. It’s not a particularly good one. But you don’t need to use that wrapper at all, the HttpClient itself is dead simple to utilize. Here’s a code sample you can build on:
Note that you would most likely be using a JSON library to serialize a POJO and create the request JSON.