Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/295.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 使用截图将用户名和密码发布到php,将返回的json数组解析为共享首选项_Java_Php_Android_Json_Android Volley - Fatal编程技术网

Java 使用截图将用户名和密码发布到php,将返回的json数组解析为共享首选项

Java 使用截图将用户名和密码发布到php,将返回的json数组解析为共享首选项,java,php,android,json,android-volley,Java,Php,Android,Json,Android Volley,我试图将用户名和密码发送到服务器,服务器返回一个包含用户信息的json数组。然后,我尝试存储传递到共享首选项中的信息。这是我的尝试。我试图在代码的底部详细说明信息,但字符串值显示为null private void jsonParse() { String url = "http://178.128.166.68/getUserInfo.php"; JsonObjectRequest request = new JsonObjectRequest(Request.Me

我试图将用户名和密码发送到服务器,服务器返回一个包含用户信息的json数组。然后,我尝试存储传递到共享首选项中的信息。这是我的尝试。我试图在代码的底部详细说明信息,但字符串值显示为null

    private void jsonParse() {
    String url = "http://178.128.166.68/getUserInfo.php";


    JsonObjectRequest request = new JsonObjectRequest(Request.Method.POST, url, null,
            new Response.Listener<JSONObject>() {
                @Override
                public void onResponse(JSONObject response) {
                    try {
                        JSONArray jsonArray = response.getJSONArray("profileData");

                        for (int i = 0; i < jsonArray.length(); i++) {
                            JSONObject profileData = jsonArray.getJSONObject(i);

                            id = profileData.getString("id");
                            fNameGet = profileData.getString("fName");
                            lNameGet = profileData.getString("lName");
                            phoneGet = profileData.getString("phone");
                            joinedDateGet = profileData.getString("joined");
                            noOfTripsGet = profileData.getString("noOfTrips");


                        }

                        SharedPreferences settings = getSharedPreferences("myData", Context.MODE_PRIVATE);
                        SharedPreferences.Editor editor = settings.edit();
                        editor.putString("phone", phoneGet);
                        editor.putString("fName", fNameGet);
                        editor.putString("lName", lNameGet);
                        editor.putString("joined", joinedDateGet);
                        editor.putString("Trips", noOfTripsGet);

                        editor.commit();


                    } catch (JSONException e) {
                        e.printStackTrace();
                    }
                }
            }, new Response.ErrorListener() {
        @Override
        public void onErrorResponse(VolleyError error) {
            error.printStackTrace();
        }
    }) {
        @Override
        protected Map<String, String> getParams() {
            Map<String, String> params = new HashMap<String, String>();
            params.put("user_name", username);
            params.put("password", password);

            return params;
        }

    };

    mQueue.add(request);
    Toast.makeText(this, id + fNameGet + lNameGet, Toast.LENGTH_LONG).show();
}
}
$username = $_POST["user_name"];
$pass = $_POST["password"];


$qry = "select * from user where phone like '$username' and pass = '$pass';";

$result = mysqli_query($conn, $qry) or die (mysqli_error($conn));

$rows=array();

while($row = mysqli_fetch_array($result)) {
    $rows[] = $row;
}

echo json_encode(array('profileData' =>$rows));


mysqli_close($conn);
?>

由于我对此缺乏经验,任何批评或帮助都将不胜感激。

愚蠢的问题可能是
phone
专栏与
username
真的一样吗?在该查询中,您应该使用
=
而不是
类似的
,您应该使用像postman这样的应用程序来查看数据从数据库返回的内容服务器java端是否有调试器,以便查看返回的内容。这可能是mysqli_error($conn)
no的输出。这不是一个愚蠢的问题,我本来打算使用用户名登录,但我把它改成了电话号码。只是我很懒,还没有改变。很抱歉给你带来了混乱
$username = $_POST["user_name"];
$pass = $_POST["password"];


$qry = "select * from user where phone like '$username' and pass = '$pass';";

$result = mysqli_query($conn, $qry) or die (mysqli_error($conn));

$rows=array();

while($row = mysqli_fetch_array($result)) {
    $rows[] = $row;
}

echo json_encode(array('profileData' =>$rows));


mysqli_close($conn);
?>