I am trying to get the output of my below mentioned php json results into my android app through JSON but i am getting only the first entry only in my android app sqlite as fetched result where it might be all rows retured by php json_encode.I would like to request assistance of how i can get all rows and i pass it to sqlite.
{"error":false,"user":{"id":1,"sutdentId":1,"user_id":"1","full_name":"Mugisha John","school":"APAPER I","level":"Level 2","year":18}}{"error":false,"user":{"id":2,"sutdentId":2,"user_id":"1","full_name":"Marie Ange Karamuzi","school":"Gs.st Joseph de Gitarama","level":"Sinior 6","year":20}}{"error":false,"user":{"id":3,"sutdentId":3,"user_id":"1","full_name":"Niragire Sangano Charles","school":"Gs. shyogwe","level":"Sinior 4","year":20}}
i only get in my android app sqlite this first row:
{"id":1,"sutdentId":1,"user_id":"1","full_name":"Mugisha John","school":"APAPER I","level":"Level 2","year":18}
Main activity.java method i use to get above result in android:
private void GetStudentDetail(final String mobile) {
// Tag used to cancel the request
String tag_string_req = "req_Verfication";
progressBarList.setVisibility(View.VISIBLE);
// myList.setVisibility(View.GONE);
StringRequest strReq = new StringRequest(Request.Method.POST,
Config.FETCH_StudentsOfParent_URL, new Response.Listener<String>
() {
@Override
public void onResponse(String response) {
Log.d(TAG, "cerfication Response: " + response.toString());
// Parsing json
for (int i = 0; i < response.length(); i++) {
try {
JSONObject jObj = new JSONObject(response);
boolean error = jObj.getBoolean("error");
// Check for error node in json
if (!error) {
// user successfully exist in database
JSONObject user = jObj.getJSONObject("user");
String id = user.getString("id");
String sutdentId = user.getString("sutdentId");
String full_name = user.getString("full_name");
String year = user.getString("year");
String school = user.getString("school");
String level = user.getString("level");
// pass id ,sutdentId, fullname ,year ,school and level
to sqlite
db.addUser(id, sutdentId, full_name, year, school, level);
progressBarList.setVisibility(View.GONE);
myList.setVisibility(View.VISIBLE);
}
else{
// Error in login. Get the error message
// hiding the progress bar
progressBarList.setVisibility(View.GONE);
myList.setVisibility(View.VISIBLE);
String errorMsg = jObj.getString("error_msg");
Toast.makeText(getActivity(), errorMsg,
Toast.LENGTH_LONG).show();
}
} catch (JSONException e) {
// JSON error
e.printStackTrace();
Toast.makeText(getActivity(), "Json error: " +
e.getMessage(), Toast.LENGTH_LONG).show();
}
}
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
Log.e(TAG, "Verfication error Error: " + error.getMessage());
Toast.makeText(getActivity(),
"response error", Toast.LENGTH_LONG).show();
// Toast.makeText(getApplicationContext(),
// error.getMessage(), Toast.LENGTH_LONG).show();
// hiding the progress bar
progressBarList.setVisibility(View.GONE);
myList.setVisibility(View.VISIBLE);
}
}) {
@Override
protected Map<String, String> getParams() {
// Posting parameters to verfication url
Map<String, String> params = new HashMap<String, String>();
params.put("mobile", mobile);
return params;
}
};
// // Adding request to request queue
MyApplication.getInstance().addToRequestQueue(strReq,tag_string_req);
}