簡體   English   中英

凌空圖書館Android

[英]Volley Library Android

我有一個關於Google Volley Library的問題。 我創建了一個php文件來檢查以下狀態

  1. 是發帖請求嗎
  2. 它會變成什么變量

看起來像這些

if($_SERVER["REQUEST_METHOD"]=="POST"){
    include 'connection.php';
    showClassmates();
}

function showClassmates(){
    global $connect;

    if(isset($_POST['table'])){

        $row = mysqli_real_escape_string($connect, strtolower($_POST['table']));

        $query = " Select * FROM $row; ";

        $result = mysqli_query($connect, $query);
        $number_of_rows = mysqli_num_rows($result);

        $temp_array = array();

        if($number_of_rows > 0){
            while ($row = mysqli_fetch_assoc($result)){
                $temp_array[] = $row;
            }
        }

        header('Content-Type: application/json; charset=UTF-8');
        echo json_encode(array("classmates"=>$temp_array));
        mysqli_close($connect);

    }

}

現在,我想使用Android應用程序加載此列表。 我為此創建了一個布局資源。 之后,我閱讀了凌空文檔,我認為從mysql表加載json數據是個好主意。 但是我不知道如何在一個請求中創建表名並加載標題字符集列表。 有人知道嗎? 感謝您的幫助:D

哦,這是我老師的一項家庭作業項目,我認為他討厭我xD,但重要的是,它的等級為:(

我使用此代碼來獲取json數據,但如何解決post [table]問題?


JsonObjectRequest jsonObjectRequest =新的JsonObjectRequest
(Request.Method.POST,
showUrl,新的Response.Listener(){
@Override
public void onResponse(JSONObject response){
嘗試{
JSONArray產品= response.getJSONArray(“ products”);

for(int i = 0; i <classmates.length(); i ++){
JSONObject classmatelist = classmates.getJSONObject(i);

字符串classmate = product.getString(“ classmate”);

items.add(classmates);
}
} catch(JSONException e){
e.printStackTrace();
}
adapter.notifyDataSetChanged();
}
},新的Response.ErrorListener(){
@Override
公共無效onErrorResponse(VolleyError錯誤){
Toast.makeText(getApplicationContext(),R.string.error_toast,> Toast.LENGTH_LONG).show();
}
});
requestQueue.add(jsonObjectRequest);

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM