开发者

How can I send an array of arrays with android's httppost

开发者 https://www.devze.com 2023-03-13 05:34 出处:网络
I would like to send an a开发者_开发百科rray of arrays from an android phone to a server. Is there any possibility to do this?

I would like to send an a开发者_开发百科rray of arrays from an android phone to a server. Is there any possibility to do this?

I expect something like this at the server side:

$_POST['items'] = array(
    array('name'=>'joe', 'email'=>'joe@example.com'), 
    array('name'=>'jane', 'email'=>'jane@example.com')
);

Thx for your help!


Use HttpPost to send data to the server, and use json to create an array of array's. nameValuePairs will carry the data:

HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost("http://www.yoursite.com");

List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(1);         
nameValuePairs.add(new BasicNameValuePair("items", jsonObject));

httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));

HttpResponse response = httpclient.execute(httppost);

Hope this helps...

0

精彩评论

暂无评论...
验证码 换一张
取 消