如何将值数组从android发送到php
我想将一组值从android发送到php,插入MySQL数据库。这里我使用数组列表。我需要使用JSONObject吗?如果是,如何通过JSON发送数组值?朋友们,请帮帮我 这是我的密码如何将值数组从android发送到php,php,android,mysql,json,arrays,Php,Android,Mysql,Json,Arrays,我想将一组值从android发送到php,插入MySQL数据库。这里我使用数组列表。我需要使用JSONObject吗?如果是,如何通过JSON发送数组值?朋友们,请帮帮我 这是我的密码 ArrayList<NameValuePair> al = new ArrayList<NameValuePair>(); String id[]={"anu","bavi","citi" }; List<String> stfids=new ArrayList<St
ArrayList<NameValuePair> al = new ArrayList<NameValuePair>();
String id[]={"anu","bavi","citi" };
List<String> stfids=new ArrayList<String>();
for(int i=0;i<2;i++)
{
stfids.add(id[i]);
}
for (int i = 0; i < 2; i++)
{
al.add(new BasicNameValuePair("names["+i+"]",String.valueOf(stfids.get(i))));
}
String response = CustomHttpClient.executeHttpPost("http:\\192.168.1.1\my-folder\myfile.php",al);
String result = response.toString();
ArrayList al=new ArrayList();
字符串id[]={“anu”、“bavi”、“citi”};
List stfids=new ArrayList();
对于(inti=0;i您可以使用JSONObject,它可以将数组作为json元素
例如:
JSONObject jsonObject = new JSONObject();
JSONArray jsonArray = new JSONArray();
try {
jsonObject.put("jsonArray",jsonArray);
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
您可以这样发送:
JSONObject jObject = new JSONObject();
try
{
jObject.put("emailID", "data");
}catch(Exception ex){}
并将其发送为:
jObject.toString();
那么我如何将其传递到php文件?我的php代码是否正确?请不要要求接受答案。如果你只是将OP部分推到不同的方向,当然不会。php的不同帖子是没有意义的,因为它必须一起编码。
jObject.toString();