First, I want to add all ArrayList Values into JsonObject then I want to add these JSON object to JsonArray I have done wright in the first I have added all ArrayList to JsonObject but I can't add all JsonObject to JsonArray.
This is my code to convert json object to json Array:-
submit.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
JSONArray jsonArray = new JSONArray();
JSONObject jsonObject = new JSONObject();
for (int i = 0; i < records.size(); i++) {
try {
jsonObject.put("sid", records.get(i).getsid());
jsonObject.put("name", records.get(i).getpName());
jsonArray.put(jsonObject));
} catch (JSONException e) {
e.printStackTrace();
}
}
Log.e("ATTENDANCE", jsonArray.toString() + "");
}
});
I am getting only the last value of the ArrayList please help me I want The output to be like these
[
{
"student_no":"3924/08",
"firstname":"olana
},
{
"student_no":"4011/08",
"firstname":"yallem"
}
]