1
我正在面对json解析器错误,我不知道是什么原因导致它,因为有时它的工作正常有时只是弹出错误,我的数据没有更新进入数据库。数据将被张贴到php文件中以加密并更新到数据库。有时它可以将数据插入到数据库中,当它不能时,它会显示json解析错误。JSON解析:解析数据时出错org.json.JSONException:输入字符0的末尾
这是我的错误:
08-31 01:10:55.598: E/JSON Parser(360): Error parsing data org.json.JSONException: End of input at character 0 of
这是我的代码:
String email = db.getEmail();
String currentPassword = cpCurrentPassword.getText().toString();
String newPassword = cpNewPassword.getText().toString();
// Building Parameters
List<NameValuePair> params = new ArrayList<NameValuePair>();
params.add(new BasicNameValuePair("email", email));
params.add(new BasicNameValuePair(
"currentpassword", currentPassword));
params.add(new BasicNameValuePair("newpassword",
newPassword));
JSONObject json = jsonParser
.makeHttpRequest(
newpassword_url, "POST",
params);
try {
int success1 = json1
.getInt(TAG_SUCCESS);
if (success1 == 1) {
showToast("Password successfully changed!");
这是我的PHP:
<?php
// array for JSON response
$response = array();
// check for required fields
if (isset($_POST['email']) && isset($_POST['newpassword'])){
$email = $_POST['email'];
$newpassword = $_POST['newpassword'];
}
// include db connect class
require_once __DIR__ . '/db_connect.php';
// connecting to db
$db = new DB_CONNECT();
$result = mysql_query("UPDATE users SET encrypted_password = '$newpassword' WHERE email = '$email'");
// check if row inserted or not
if ($result) {
// successfully updated
$response["success"] = 1;
$response["message"] = "Password successfully changed";
// echoing JSON response
echo json_encode($response);
}
?>
即使数据没有更新到数据库,我的成功标签仍然会回应1.这是我不明白的地方。
这不是很明显的是jsonParser的类型, json1从哪里来,它是什么类型, –
另外,侧面说明。您正在将密码存储在数据库的“encrypted_password”列中(这不安全)。 –
@VictorRonin我不明白你的第一个问题。至于简单的密码,即时通讯使用sha512加密盐。 –