Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/188.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/json/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何使用JSON(Android)将多行(或列表对象)发布到PHP_Android_Json - Fatal编程技术网

如何使用JSON(Android)将多行(或列表对象)发布到PHP

如何使用JSON(Android)将多行(或列表对象)发布到PHP,android,json,Android,Json,我正在创建一个使用SQLite的android应用程序。我有一个表,其中有5个字段。该表中有很多行,我希望使用JSON将所有这些行发送到我的PHP代码中,以便接收对象并将其插入MySQL数据库 最好的方法是什么。我正在使用LIST对象,但不知道如何使用JSON发布它 请导游 我正在使用这个代码 mCursor =db.rawQuery("SELECT * FROM customer", null); while (mCursor.moveToNext()) {

我正在创建一个使用SQLite的android应用程序。我有一个表,其中有5个字段。该表中有很多行,我希望使用JSON将所有这些行发送到我的PHP代码中,以便接收对象并将其插入MySQL数据库

最好的方法是什么。我正在使用LIST对象,但不知道如何使用JSON发布它

请导游

我正在使用这个代码

mCursor =db.rawQuery("SELECT * FROM customer", null);

           while (mCursor.moveToNext()) {
                // In one loop, cursor read one undergraduate all details
                // Assume, we also need to see all the details of each and every undergraduate
                // What we have to do is in each loop, read all the values, pass them to the POJO class
                //and create a ArrayList of undergraduates
               customer = new Customer();   
               customer.CustomerName = mCursor.getString(0).toString();
               customer.Phone = mCursor.getString(1).toString();
               customer.BrandName = mCursor.getString(2).toString();
               customer.City = mCursor.getString(3).toString();
               customer.FamilyMembers = mCursor.getString(4).toString();

               customerList.add(customer);                 

            }
for (int i = 0; i < customerList.size(); i++) 
                {
                    JSONObject row = new JSONObject();
                    row.put("Customer", customerList.get(i));                        
                    json.put(row);
                }
mCursor=db.rawQuery(“选择*来自客户”,空);
while(mCursor.moveToNext()){
//在一个循环中,游标读取所有细节
//假设,我们还需要查看每个本科生的所有详细信息
//我们要做的是在每个循环中,读取所有值,将它们传递给POJO类
//创建一个大学生列表
客户=新客户();
customer.CustomerName=mCursor.getString(0.toString();
customer.Phone=mCursor.getString(1.toString();
customer.BrandName=mCursor.getString(2.toString();
customer.City=mCursor.getString(3.toString();
customer.FamilyMembers=mCursor.getString(4.toString();
customerList.add(客户);
}
对于(int i=0;i

不知道如何将其发布到PHP代码。

您必须遍历列表,并在JSONArray中为每一行填充JSONObject。在JSONObject中,可以使用键作为列名,并使用所需类型的值

JSONArray json = new JSONArray();
for (int i = 0; i < list.size(); i++) {
    JSONObject row = new JSONObject();
    row.put("key1", list.get(i).value1);
    ...
    json.put(row);
}

分解您的问题,将表中的一个字段发送到php后端(这将为您提供JSON和POST的答案)。然后发送所有5个字段(这扩展了JSON的使用)。然后发送多行(学习列表界面)。你会发现它更容易。谢谢你,布伦德尔!我可以通过JSON轻松地将值对作为参数发布。使用httpRequest。但是我需要知道如何创建JSON对象的列表,然后使用HTTPRequest将其作为JSON列表或字符串或其他任何形式发送。。!那么你应该在你的问题中发布一些代码。要发送列表,您需要将其作为值对中的值发送。你可以阅读JSON规范来了解如何制作JSON数组。布伦德尔,我已经在最初的问题中添加了代码。谢谢你的建议,谢谢。我要试试这个。如何将json传递给PHP?这样地?SendHttpPost(Url,jsonObject);
$jsonstring = file_get_contents('php://input', true);