【问题标题】:Sending ArrayList to server not working with AsyncHttp将 ArrayList 发送到服务器不使用 AsyncHttp
【发布时间】:2017-08-15 07:07:10
【问题描述】:
HttpAsyncRequest request = new HttpAsyncRequest(
                               MapsActivity.this, 
                               Constant.BaseUrl, 
                               HttpAsyncRequest.RequestType.GET, 
                               new MarkerParser(), listener);
request.addParam("array",arr);  //this is not working
request.execute();

我想将 latlng 的数组列表发送到我正在使用 http 请求的服务器,但我们只能通过它发送字符串。如何发送 latlng 的数组列表?

【问题讨论】:

  • 这到底是什么库?
  • loopj.com/android-async-http 这是我正在使用的库@MatiasOlocco
  • 你为什么不像文档说的那样使用RequestParams
  • 而且我在库中也没有看到该类,您使用的是最新版本吗?我建议您切换到维护更完善的库,例如 Retrofit
  • 1.当我长按地图时,标记将在地图上设置等等有一个我想在 php 服务器上发送的 latlng 数组列表

标签: android post arraylist android-async-http


【解决方案1】:

这就是我如何将我的 latlng 数组列表传递给 JSONARRAY,然后转换为字符串,然后发送到服务器。

JSONArray pointsinjsonarray=new JSONArray();

                    for(int i=0;i<arraylistofmarkers.size();i++) {
                        try {
                            pointsinjsonarray.put(i,arraylistofmarkers.get(i));

                        } catch (JSONException e) {
                            e.printStackTrace();
                        }

pointsinjsonarray.toString();

【讨论】:

    【解决方案2】:

    正如我在我的 cmets 中所说,我不知道您从哪里获得该课程(也许是您自己的...)。在文档中它说您应该执行以下操作:

    RequestParams params = new RequestParams();
    params.put("array", arr);
    AsyncHttpClient client = new AsyncHttpClient();
    //listener is an instance of AsyncHttpResponseHandler
    client.get(Constant.BaseUrl, listener, params);
    

    来源:http://loopj.com/android-async-http/

    【讨论】:

      猜你喜欢
      • 2015-11-12
      • 1970-01-01
      • 2019-06-07
      • 2019-10-12
      • 1970-01-01
      • 2011-05-06
      • 1970-01-01
      • 2023-03-03
      • 1970-01-01
      相关资源
      最近更新 更多