com.androidnetworking.error.ANError:org.json.JSONException:Value

问题描述 投票:-1回答:1

这是我将数据上传到我的数据库的方法...我使用了名为'com.amitshekhar.android:android-networking 0.4.0']的第三方库,.plz帮助我更快,因为我被卡住了在过去1周的错误中,我们非常重视任何回应...

 public void data_upload(final Context context, final String user_id, final String data){


    Toast.makeText(context,user_id+data,Toast.LENGTH_SHORT).show();
    Log.i("tagconvertstr", "["+user_id+"]");

    AndroidNetworking.post(data_upload_url)
            .addBodyParameter("action","data_upload")
            .addBodyParameter("user_id",user_id.toString())
            .addBodyParameter("data",data)
            .build()
            .getAsJSONArray(new JSONArrayRequestListener() {



                @Override
                public void onResponse(JSONArray response) {
                    Log.i("tagconvertstr", "["+user_id+"]"+data);
                        if(response != null){
                            try{
                                String responsestring = response.get(0).toString();
                                Toast.makeText(context,"PHP server response"+responsestring,Toast.LENGTH_SHORT).show();

                                if(responsestring.equalsIgnoreCase("Success")){
                                    Toast.makeText(context,"php was successful",Toast.LENGTH_SHORT).show();
                                }
                                else{
                                    Toast.makeText(context,"php was unsuccessful",Toast.LENGTH_SHORT).show();
                                }

                            }
                            catch (JSONException e){
                                e.printStackTrace();
                                Toast.makeText(context,"good,but java cant parse json which it recieved"+e.getMessage(),Toast.LENGTH_SHORT).show();
                            }
                        }else{
                            Toast.makeText(context,"xyz",Toast.LENGTH_SHORT).show();
                        }

                    }

                @Override
                public void onError(ANError anError) {
                    Toast.makeText(context,"unsuccesfull:error is"+anError.getMessage(),Toast.LENGTH_SHORT).show();
                    Log.i("tagconvertstr", "["+anError.toString()+"]");
                    Log.i("tagconvertstr", "["+user_id+"]"+data);

                }
            });
}

这是我的PHP代码...

public function select(){
$conn=$this->connects();
if($conn != null){
    $name = "Muthuselvan Chandran";//$_POST["name"];
 $sql_count_data = "SELECT data FROM notes_data WHERE Name LIKE '$name'";
 $count_data = mysqli_query($conn,$sql_count_data);
    if($count_data){
        while($data = mysqli_fetch_array($count_data)){
            $spacecrafts[] = $data;
        }
        print (json_encode($spacecrafts));

    }else{
        print (json_encode(array("PHP EXCEPTION CAN'T RETRIEVE FROM MYSQL")));
    }
    }else{
        print(json_encode(array("PHP EXCEPTION : CAN'T CONNECT TO MYSQL.NULL CONNECTION")));
    }
    mysqli_close($conn);
}

而且我已经在另一个名为data_upload.php的文件中称呼它

 <?php

require_once("DBadapter.php");

if($_POST["action"]=="data_upload"){
    $dbAdapter = new DBadapter();
$Name = $_POST["Name"];
$data = $_POST["data"];
$dbAdapter->insert(array($Name,$data));

 }

  ?>

并且当单击按钮时,我已经调用了data_upload方法。...

    backup.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            for(String name : notes)
            {

            data_transfer data_transfer = new data_transfer();
            data_transfer.data_upload(getApplicationContext(),user_id.get(0),name);
            }
        }
    });

这是我将数据上传到数据库的方法...我使用了名为'com.amitshekhar.android:android-networking 0.4.0'.. plz的第三方库,因为我被卡在此错误中, ...

android mysql android-studio android-volley android-networking
1个回答
0
投票
© www.soinside.com 2019 - 2024. All rights reserved.