dsy19811981 2012-05-03 14:11
浏览 34
已采纳

Android ArrayList <String []>到PHP

I need my app to send an ArrayList<String[]> to php, I have this to call the service:

ArrayList<String[]> Items = new ArrayList<String[]>();
(...)
JSONObject JSONSend= new JSONObject();
JSONSend.put("Items", Items );

HttpConnectionParams.setConnectionTimeout(client.getParams(), 10000);
HttpResponse response;
HttpPost post = new HttpPost(SERVICE);
post.setHeader("json", JSONSend.toString());
StringEntity se = new StringEntity(JSONSend.toString());
se.setContentEncoding(new BasicHeader(HTTP.CONTENT_TYPE,"application/json"));
post.setEntity(se);
response = client.execute(post);

and on the PHP service:

$data = file_get_contents('php://input');
$json = json_decode($data);
$Items = $json->{'Items'};
error_log($Items);

and the php is returning this:

[[Ljava.lang.String;@413e2fd0, [Ljava.lang.String;@413a2940, [Ljava.lang.String;@4139df18, [Ljava.lang.String;@4141b5b0, [Ljava.lang.String;@413931c8, [Ljava.lang.String;@41348b40, [Ljava.lang.String;@41393928]

The type of the $ServMade is string, so how can I take care of the data as an array on php? Am I missing something?

  • 写回答

2条回答 默认 最新

  • dongpei3245 2012-05-03 14:34
    关注

    Try the following when generating json string in android:

    JSONObject JSONSend= new JSONObject();
    JSONArray ja = null;
    JSONArray tmp = new JSONArray();
    for(String s[] : Items){
        ja = new JSONArray();
        for(int i = 0; i<s.length; i++)
            ja.put(s[i]);
        tmp.put(ja);
    }
    JSONSend.put("Items", tmp);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!
  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?
  • ¥15 求daily translation(DT)偏差订正方法的代码
  • ¥15 js调用html页面需要隐藏某个按钮