0

我如何使用 for 循环和 StringRequest 来获取 mysQl 数据库中的所有数据,所以这是我的代码`

      StringRequest jsonObjectRequest = new StringRequest(Request.Method.GET, url,
            new Response.Listener<String>() {
                @Override
                public void onResponse(String response) {

                    try {
                        JSONObject jObj = new JSONObject(response);
                        boolean error = jObj.getBoolean("error");

                        if (!error) {
                            for(int i=0;i<jObj.length();i++){

                            String user = jObj.getJSONObject("user").getString("name");
                            //Toast.makeText(getApplicationContext(), "Hi     " + user +", You are login!", Toast.LENGTH_SHORT).show();
                            // Launch User activity


                           // finish();
                        }} else {

                            String errorMsg =jObj.getString("error_msg");
                            Toast.makeText(getApplicationContext(),
                                    errorMsg, Toast.LENGTH_LONG).show();
                        }
                    } catch (JSONException e) {
                        e.printStackTrace();
                    }`
4

0 回答 0