Php 如何使用Json解析来自服务器的数据?
这是我的php文件。我想将android中的数据解析为JSON对象。我可以这样做吗Php 如何使用Json解析来自服务器的数据?,php,android,json,Php,Android,Json,这是我的php文件。我想将android中的数据解析为JSON对象。我可以这样做吗 <?php include("../include/connection.php"); $old_pass="1234"; $new_pass="123"; $re_pass="123"; $contact_no="8285663445"; $chg_pwd="select * from users where contact_no='$contact_no'";
<?php
include("../include/connection.php");
$old_pass="1234";
$new_pass="123";
$re_pass="123";
$contact_no="8285663445";
$chg_pwd="select * from users where contact_no='$contact_no'";
$data=mysqli_query($conn,$chg_pwd) or die(mysqli_error($conn));
$chg_pwd1=mysqli_fetch_array($data);
$data_pwd=$chg_pwd1['password'];
if($data_pwd==$old_pass){
if($new_pass==$re_pass){
$update_pwd="update users set password='$new_pass' where contact_no='$contact_no'";
$updata=mysqli_query($conn,$update_pwd) or die(mysqli_error($conn));
$json = array("status" => 1, "msg" => "password reset successfully");
}
else{
$json = array("status" => 0, "msg" => "Your new and Retype Password is not match!");
}
}
else
{
$json = array("status" => 0, "msg" => "Request method not accepted");
}
header('Content-type: application/json');
echo json_encode($json);
?>
这就是我在日志中看到的
0-09 15:33:23.578 23721-25138/com.pickpamphlet.easydeals E/mapvalue{old_pass=12345,contact_no=8947897487,re_pass=zxcvbnm,new_pass=zxcvbnm}
10-09 15:33:24.813 23721-23721/com.pickpamphlet.easydeals E/log:{状态:0,消息:请求方法未接受}'
Android代码中的JSON解析已正确完成 1234不是数据库中的密码。请检查您的情况是否正确
if($data_pwd==$old_pass){
}
else
{
$json = array("status" => 0, "msg" => "Request method not accepted");
}
正确检查php条件,确保传递的值正确。谢谢。问题出在我的php脚本中。
if($data_pwd==$old_pass){
}
else
{
$json = array("status" => 0, "msg" => "Request method not accepted");
}