0

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.

2
  • try json.put("DTSent", Long.toString(dateTime.getTimeInMillis())); Commented Jun 12, 2013 at 13:05
  • It receives exactly what you're sending it. ID is an array which does not override toString() Commented Jun 12, 2013 at 13:11

2 Answers 2

4

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

Sign up to request clarification or add additional context in comments.

Comments

1

You are passing in an array of strings (see the three dots?). Try using ID[0] instead.

Here is a useful post:

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.