0

For single pair value, I used:

datas.add(new BasicNameValuePair("latitude", Double.toString(lastKnownLocation.getLatitude())));

Then send it to server using HttpClient:

HttpClient httpclient = CustomHttpClient.getHttpClient();
HttpPost httppost = new HttpPost(url);
httppost.setEntity(new UrlEncodedFormEntity(datas));
HttpResponse response = httpclient.execute(httppost);
HttpEntity entity = response.getEntity();
input = entity.getContent();

At server side, I extract this information as follows:

$latitude = (_POST['latitude']);

But for an array of my own type, says Place with 3 fields:

class Place {
     int id;
     String name;
     String address;
}

How can I send this information to my php script? And within my php, how can I extract this JSON array?

1
  • The best way is to use JSON I guess. On php side, use json_decode to retrieve data on the php side. There is plenty of example to send json objects from an Android application. Commented Jan 20, 2012 at 4:03

1 Answer 1

1

There are countless methods to transfer data, but one of the more common data-interchange methods is via JSON.

See this question for how to do that. In a nutshell, you

  • add JSON support to your "beans," or the elements that you want to transport,
  • convert the relevant beans to JSON, and
  • send an HTTP request to the remote server, including the JSON data.

See qklxtlx's response for how to interpret the JSON on the server side.

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

3 Comments

Thanks. Could you provide a minimal working example? The link you gave showed how to send data to php server, but the code didn't submit any "key-pair". So at server side, how could I retrieve this JsonArray?
@Chan Check out the other answer in that link, authored by primpop.
@Chan Updated answer with your 2nd question.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.