Reputation: 45
So I'm developing an Android app (Java) that posts a JSON object to a web server. I've achieved this, but I'm battling to get the string value to display properly. Instead of the server receiving "6666666666666", it receives "Ljava.lang.String;@41108be0]". How on earth do I go about fixing this? Here's my code:
protected Boolean doInBackground(String... ID) {
HttpClient httpClient = new DefaultHttpClient();
Date dateTime = new Date();
string deviceID=null;
try {
HttpPost request = new HttpPost("http://192.168.1.89:80/");
JSONObject json = new JSONObject();
json.put("IDNo", ID.toString());
json.put("DTSent", dateTime);
json.put("DeviceID", deviceID);
StringEntity se = new StringEntity(json.toString(), "UTF-8");
se.setContentType("application/json; charset=UTF-8");
request.setEntity(se);
request.setHeader( "Content-Type", "application/json");
}
Please help.
Upvotes: 0
Views: 796
Reputation: 9242
You are passing in an array of strings (see the three dots?). Try using ID[0] instead.
Here is a useful post:
Upvotes: 1
Reputation: 5337
ID is a String-Array not just a string. the ...
makes it an array. so either use ID[0]
or remove the ...
from the function declaration
Upvotes: 4