Click here to Skip to main content
15,903,175 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Laravel code:
$Questions = (Questions::all());
$arr = array();
foreach ($Questions as $Question){
  $arr[] = $Question ;
}

return $arr ;



and volley (android)

public void getMainQuestions(final OnRecievedMainQuestion onRecievedMainQuestion) {

          JsonArrayRequest request = new JsonArrayRequest(Request.Method.GET, "http://192.168.1.4:8000/api/mainQuestion", null, new Response.Listener<JSONArray>() {
              @Override
              public void onResponse(JSONArray response) {
                  Question question = new Question();
                  ArrayList<Question> questions = new ArrayList<>();
                    for (int i = 0; i < response.length(); i++) {
                      try {
                          question.setId(response.getJSONObject(i).getInt("id"));
                          question.setTitle(response.getJSONObject(i).getString("title"));
                          question.setContent(response.getJSONObject(i).getString("content"));
                          questions.add(question);
                      } catch (JSONException e) {
                          e.printStackTrace();
                      }
                  }
                  onRecievedMainQuestion.Recivied(questions);

              }
          }, new Response.ErrorListener() {
              @Override
              public void onErrorResponse(VolleyError error) {

              }
          });
          request.setRetryPolicy(new DefaultRetryPolicy(18000, DefaultRetryPolicy.DEFAULT_MAX_RETRIES, DefaultRetryPolicy.DEFAULT_BACKOFF_MULT));
          Volley.newRequestQueue(context).add(request);

  }


What I have tried:

i'm trying to getting data from server(Laravel) using Volley library of android but just getting once of data in jsonObjects(i has one json and i have serveral
jsonObject in JsonArray) but i can't get all of items from jsonObject. why this is happen?
Posted
Updated 31-Mar-19 2:26am
Comments
David Crow 1-Apr-19 10:18am    
In the onResponse() method, what is returned from response.length()?

After the for() loop, how many items are in questions?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900