ArrayList的传递到PHP采用Android异步HTTP客户端文档 [英] Passing ArrayList to PHP using Android Asynchronous Http Client Issue

查看:111
本文介绍了ArrayList的传递到PHP采用Android异步HTTP客户端文档的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试着去送的ArrayList到PHP($ _ POST),并把它作为一个数组。
我使用Android异步HTTP客户端 http://loopj.com/android-async-http/

Im trying to send ArrayList to PHP ($_POST) and use it as an array. I use Android Asynchronous Http Client http://loopj.com/android-async-http/

我的code

ArrayList<String> array = new ArrayList<String>();
array.add("1");
array.add("2");
array.add("3");
RequestParams params = new RequestParams();
params.put("descr_array", array );
AsyncHttpClient client = new AsyncHttpClient();
client.post(StaticValues.SERVER_PAGE, params, new AsyncHttpResponseHandler() { ... }

在PHP

$descrarray[] = $_POST['descr_array'];

显示只有一个项目,作为一个字符串。

shows only one item, as a string.

$result = print_r($_POST);
print(json_encode($result));

调试code显示

Debugging code shows

阵列([descr_array] => 1)

Array ( [descr_array] => 1 )

有只有一个字符串,我该怎么解决呢?

There is only one string, how can I solve it?

推荐答案

如果你想获得的所有值写:

If you want to get all values write:

RequestParams params = new RequestParams();
params.put("descr_array_1", array.get(0) );
params.put("descr_array_2", array.get(1) );
params.put("descr_array_2", array.get(2) );

但我你使用 GSON preFER转换数组和字符串使用一对仅:

But I prefer you to use Gson to convert Array to String and use one pair only:

Gson gson = new Gson(); 
String out = gson.toJson(array);
params.put("descr_array", out ); 

这篇关于ArrayList的传递到PHP采用Android异步HTTP客户端文档的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆