Seemingly simple question, but no obvious answer found online.
At this link, there is a tutorial on posting simple name value pairs to a file from within an android app. http://www.androidsnippets.com/executing-a-http-post-request-with-httpclient
What I want to do is post ‘something’ which on the receiving end (a php script) can be accessed as an array.
In PHP I want to receive:
$_POST[‘array’]=array(“key”=>”value”,”key2″=>”value2″);
Being relatively new to android development, perhaps someone could elaborate on creating a similar thing in Java, and then how one cant send it – setEntity seems to only take namevaluepairs…
Many Thanks
You should use a JSON Wrapper both in Android App and your PHP server.
In PHP you should use
json_decode(), like:$thingFromPost = json_decode($data).In Java, there are many ways to create a JSONArray. A basic example would be:
And after that, you just send your array with a HttpPost to your server.
If you need a detailed tutorial how to make requests using JSON in Android, follow this link.
Hope it helps!