StringRequest for循环

时间:2017-03-14 17:20:16

标签: android mysql json android-volley jsonobjectrequest

我如何使用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();
                    }`

0 个答案:

没有答案