Php Json异常:字符串类型的值连接可以';不能转换为对象
这是我的insert.php脚本Php Json异常:字符串类型的值连接可以';不能转换为对象,php,android,json,sqlite,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();
<?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);
?>
有什么问题吗?尝试将内容类型设置为
json
ex:在浏览了这个链接之后,我添加了一个。标题('Content-type:application/json;charset=utf-8');对于开始的go php脚本…我的应用程序仍然抛出JsonException:String类型的值连接无法转换为JsonObject..任何解决方案?这会打印什么:Log.i(“R”,“Response is”+s);?谢谢问题是,我有一个回应“工作”的声明;正因为如此,它才显示出这样的错误
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());
}
}
org.json.JSONException: Value Connection of type java.lang.String cannot be converted to JSONObject