Json异常:String类型的值连接无法转换为对象

时间:2017-07-09 19:53:12

标签: php android json sqlite

这是我的insert.php脚本

<?php

$name=$_POST['Name'] ?? ''  ;
$address=$_POST['Address'] ?? '' ;

include("db_config.php");

$result = mysqli_query($con,"INSERT INTO `Firm`(`ID`,`NAME`,`ADDRESS`) VALUES ('','$name','$address')");    

$response = array();
 if($result){
    $response['success']=1;
    $response['message']="Record Inserted Successfully-".$result."--";
 }
else { 
    $response['success']=0;
    $response['message']="Insertion Failure-".$result."--";
 }

echo json_encode($response);

?>

这是响应代码

request = new StringRequest(Request.Method.POST, Utils.INSERT_FIRM, new Response.Listener<String>() {
                    @Override
                    public void onResponse(String s) {
//                        Log.i("R","Response is "+s);

                        try {
                            JSONObject jsonObject = new JSONObject(s);
                            int success = jsonObject.getInt("success");
                            String message = jsonObject.getString("message");
                            Toast.makeText(Add_Firm.this,""+message+":"+ success,Toast.LENGTH_SHORT).show();

                        } catch (Exception e) {
                            Toast.makeText(Add_Firm.this, "Some Error"+e.toString(), Toast.LENGTH_SHORT).show();
                            Log.i("Error"," "+e.toString());
                        }
                    }

我使用php脚本将android连接到数据库 当我单击应用程序中的提交按钮时 虽然插入发生在数据库但是 我一直在android

中得到这个异常
org.json.JSONException: Value Connection of type java.lang.String cannot be converted to JSONObject

问题是什么?

0 个答案:

没有答案