gpt4 book ai didi

php - 由于 DATETIME 数据,java.lang.String 类型的值
转载 作者:行者123 更新时间:2023-11-29 19:04:57 24 4
gpt4 key购买 nike

我一直在努力尝试将数据成功插入 MySQL 数据库(使用 Volley),这不是问题,因为数据已插入,但我一直遇到此错误 W/System.err: org.json.JSONException:类型 java.lang.String 的值 < br 无法转换为 JSONObject 或 JSONEception,此错误阻止执行任何其他操作,如果我添加更多代码,UI 会卡住,我尝试从我的 php 文件中删除日期代码,一切正常,只是日期时间值不是我要查找的值,当我添加回来时,它再次显示错误。这是我的代码:

    Response.Listener<String> responseListener1 = new Response.Listener<String>() {
@Override
public void onResponse(String response) {
try {
JSONObject jsonResponse1 = new JSONObject(response);
boolean success = jsonResponse1.getBoolean("success");
if (success) {


Toast.makeText(MapActivity.this, "SUCCESS",Toast.LENGTH_LONG).show();


} else {
Toast.makeText(MapActivity.this, "INSERTION FAILED",Toast.LENGTH_LONG).show();


}


} catch (JSONException e) {
e.printStackTrace();
Toast.makeText(MapActivity.this, "EXCEPTION",Toast.LENGTH_LONG).show();
}


}
};




SendBookingRequest bookingRequest = new SendBookingRequest(idd,em,Adresse_source,duree,dist, responseListener1);
RequestQueue queue1 = Volley.newRequestQueue(MapActivity.this);
queue1.add(bookingRequest);

这是我的 php 文件 SendBookingRequest

<?php
require("password.php");
$connect = mysqli_connect("localhost", "XXXXX", "XXXXX", "XXXXX");

$driver_id = $_POST["driver_id"];
$email = $_POST["email"];
$adresse_source = $_POST["adresse_source"];
$duree = $_POST["duree"];
$distance = $_POST["distance"];
$response = array();
$dt_obj = new DateTime($response['send_moment'], new
DateTimeZone('America/Chicago'));
$dt_obj->setTimezone(new DateTimeZone('Europe/London'));
$send_time = $dt_obj->format('Y-m-d H:i:s');
echo $send_time;
function AddRequest() {
global $connect, $driver_id, $email, $adresse_source, $duree, $distance, $send_time ;
$statement = mysqli_prepare($connect, "INSERT INTO demande (driver_id, pass_id, adresse_source, duree, distance, send_moment) VALUES (?, (SELECT user_id FROM passager WHERE email = ?),?, ?, ?, ?)");
mysqli_stmt_bind_param($statement, "issdis", $driver_id, $email, $adresse_source, $duree, $distance, $send_time);
mysqli_stmt_execute($statement);
mysqli_stmt_close($statement);
}


$response["success"] = false;

AddRequest();
$response["success"] = true;


echo json_encode($response);
?>

任何帮助将不胜感激。

最佳答案

我认为你需要在 php 代码中将 header('Content-type: application/json'); 行放在 echo json_encode($response); 上方

关于php - 由于 DATETIME 数据,java.lang.String 类型的值 <br 无法转换为 JSONObject,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43581210/

24 4 0

Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com