如何从Android发送数据的数组PHP服务器? [英] How to send an array of data from Android to php server?

查看:202
本文介绍了如何从Android发送数据的数组PHP服务器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有关一对价值,我用:

datas.add(new BasicNameValuePair("latitude", Double.toString(lastKnownLocation.getLatitude())));

然后使用发送到服务器的HttpClient

HttpClient httpclient = CustomHttpClient.getHttpClient();
HttpPost httppost = new HttpPost(url);
httppost.setEntity(new UrlEncodedFormEntity(datas));
HttpResponse response = httpclient.execute(httppost);
HttpEntity entity = response.getEntity();
input = entity.getContent();

在服务器端,我提取这些信息如下:

At server side, I extract this information as follows:

$latitude = (_POST['latitude']);

但对于我自己类型的数组,表示地点 3个领域:

class Place {
     int id;
     String name;
     String address;
}

我如何将此信息发送给我的PHP脚本?而我的PHP中,我怎么能提取此JSON阵列?

How can I send this information to my php script? And within my php, how can I extract this JSON array?

推荐答案

有无数的方法来传输数据,但更常见的数据交换的方法之一是通过JSON。

There are countless methods to transfer data, but one of the more common data-interchange methods is via JSON.

请参阅this问题了解如何做到这一点。简而言之,您

See this question for how to do that. In a nutshell, you


  • 添加JSON支持你的豆,或者要运输的元素,

  • 转换相关豆JSON和

  • 发送HTTP请求到远程服务器,包括JSON数据。

请参阅qklxtlx对如何跨preT的JSON在服务器端的响应。

See qklxtlx's response for how to interpret the JSON on the server side.

这篇关于如何从Android发送数据的数组PHP服务器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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