Java 发送json数组,在android中使用截取将mysql中的多个记录添加到php脚本

Java 发送json数组,在android中使用截取将mysql中的多个记录添加到php脚本,java,php,android,mysql,android-volley,Java,Php,Android,Mysql,Android Volley,我正在尝试在数据库中添加多个记录,我正在用android中的凌空字符串请求方法向php脚本发送json数组来添加这些记录,但在php中没有得到json数组的结果。我只想在mysql中添加多个记录,这就是为什么要向脚本发送json数组,通过获取其中的所有数据来添加这些记录 这里是插入数据功能 private void InsertData() { if(arrayList.size()>0) { Toast.makeText(getApplicationContext(), "list n

我正在尝试在数据库中添加多个记录,我正在用android中的凌空字符串请求方法向php脚本发送json数组来添加这些记录,但在php中没有得到json数组的结果。我只想在mysql中添加多个记录,这就是为什么要向脚本发送json数组,通过获取其中的所有数据来添加这些记录

这里是插入数据功能

private void InsertData() {

if(arrayList.size()>0) {
Toast.makeText(getApplicationContext(), "list not null "+i+arrayList.size(), 
 Toast.LENGTH_LONG).show();

//for (i=0;i<arrayList.size();i++) {
    //Toast.makeText(getApplicationContext(),"inside for loop", Toast.LENGTH_LONG).show();


    StringRequest stringRequest = new StringRequest(Request.Method.POST,
            Constants.insert_macthes,
            new Response.Listener<String>() {
                @Override
                public void onResponse(String response) {

                    try {
                        JSONObject jsonObject = new JSONObject(response);


                        if (jsonObject.getInt("success") == 1) {

                            Toast.makeText(getApplicationContext(), jsonObject.getString("message"), Toast.LENGTH_LONG).show();

                        } else

                            Toast.makeText(getApplicationContext(), "not added", Toast.LENGTH_LONG).show();

                        dis = jsonObject.getString("message");
                    } catch (JSONException e) {
                        e.printStackTrace();
                    }
                }


            },
            new Response.ErrorListener() {
                @Override
                public void onErrorResponse(VolleyError error) {

                    if (error instanceof TimeoutError || error instanceof NoConnectionError) {
                        Toast.makeText(MyMatchas.this,
                                "Error time out",
                                Toast.LENGTH_LONG).show();
                    } else if (error instanceof AuthFailureError) {
                        //TODO
                        Toast.makeText(MyMatchas.this,
                                "Auth Error time out",
                                Toast.LENGTH_LONG).show();
                    } else if (error instanceof ServerError) {
                        //TODO
                        Toast.makeText(MyMatchas.this,
                                "Server Error time out",
                                Toast.LENGTH_LONG).show();
                    } else if (error instanceof NetworkError) {
                        //TODO
                        Toast.makeText(MyMatchas.this,
                                " Network Error time out",
                                Toast.LENGTH_LONG).show();
                    } else if (error instanceof ParseError) {
                        Toast.makeText(MyMatchas.this,
                                "Parse Error time out",
                                Toast.LENGTH_LONG).show();
                        //TODO
                    }

                }
            }) {
        @Override
        protected Map<String, String> getParams() {
            JSONArray array=new JSONArray();

            JSONObject jsonObject=new JSONObject();
            for(i=0;i<arrayList.size();i++)
            {
                Log.v("fetching record:",arrayList.get(i).getId());
                arr[i]="dog_id"+arrayList.get(i).getId()+"dog_name"+arrayList.get(i).getDog_name()+"score"+arrayList.get(i).getDog_score()+"user_id"+ String.valueOf(SharedPrefManager.getInstance(MyMatchas.this).getUserid());
                try {
                    //Log.v("put in json:",arrayList.get(i).getId());
                    jsonObject.put("dog_id",arrayList.get(i).getId());
                    jsonObject.put("dog_name",arrayList.get(i).getDog_name());
                    jsonObject.put("score",arrayList.get(i).getDog_score());
                    jsonObject.put("user_id",String.valueOf(SharedPrefManager.getInstance(MyMatchas.this).getUserid()));

                } catch (JSONException e) {
                    Log.v("error exceptiion:",arrayList.get(i).getId());
                    e.printStackTrace();
                }
                array.put(jsonObject);
            }
            HashMap<String ,String> params=new HashMap<String, String>();
            Log.v("All data:",jsonObject.toString());
            Log.v("json object data:",array.toString());
            params.put("params",array.toString());

            return params;
        }
    };


    // Creating RequestQueue.
    RequestQueue requestQueue = Volley.newRequestQueue(MyMatchas.this);

    // Adding the StringRequest object into requestQueue.
    requestQueue.add(stringRequest);

    // }
  // Toast.makeText(getApplicationContext(),dis,Toast.LENGTH_LONG).show();

 }
private void InsertData(){
如果(arrayList.size()>0){
Toast.makeText(getApplicationContext(),“列表不为空”+i+arrayList.size(),
Toast.LENGTH_LONG).show();

//对于(i=0;i您需要为每次保存新值创建新对象

 JSONArray array = new JSONArray();
 JSONObject jsonObject;
 GettingVaccineData gettingVaccineData;
 for (int i = 0; i < vaccineData.size(); i++) {
   jsonObject = new JSONObject();
   gettingVaccineData = vaccineData.get(i);
   try {

     jsonObject.put("LCID", reqResponse);
     jsonObject.put("LVID", gettingVaccineData.getID());
     jsonObject.put("LVNAME", gettingVaccineData.getNAME());
     jsonObject.put("LSCHEDULE", scheduleDays.get(i));
     jsonObject.put("LGIVEN", "NULL");
     jsonObject.put("LSTATUS", "not given");
     jsonObject.put("LHOSPITAL", "NULL");


   } catch (JSONException e) {
     e.printStackTrace();
   }
   array.put(jsonObject);
JSONArray数组=新的JSONArray();
JSONObject JSONObject;
获取疫苗数据获取疫苗数据;
对于(int i=0;i
您可以访问如下值:

echo $json[0]["dog_id"];

这是因为查询失败并且永远不会解析为
true
“INSERT INTO Match_list(dog_id,score,dog_name,User_id)”值(“$obj->dog_id',“$obj->dog_name',“$obj->score',“$obj->User_id')仍然是一个不带替换的字符串。请尝试将变量包装在{}
…值(“{$obj->dog_id},”,“{$obj->dog_name}中“…
或将它们连接起来,
…值“$obj->dog_id.”、“$obj->dog_name”。“…
请确保通过打印出来并在sql客户端中手动尝试来测试您的查询仍然存在同样的问题,无法获取数据,请帮助我解决,而且只有arraylist中的最后一个列表数据位于我在Android中使用日志消息看到的json数组上,
echo$sql\u query
$sql\u query=“插入…
?我已经尝试手动添加数据,但我认为它没有从android volley string请求方法中获取json数组,而且我已经在json数组中检查了[]方括号不在来自android的json数组中
echo $json[0]["dog_id"];