try {
jsonObjectt.put("senderId", "XYZ");
jsonObjectt.put("User_Type", usertype);
jsonObjectt.put("Text_message", message);
for(int i=0; i<=selectedUserIdListArray.size(); i++) {
try {
jsonObject.put("Stud_ID", selectedUserIdListArray.get(i));
jsonObject.put("Mobile_No", selectedUserNoListArray.get(i));
jsonArray.put(jsonObject);
}catch (Exception e){
e.printStackTrace();
}
}
jsonObjectt.put("studData",jsonArray);
} catch (JSONException e) {
e.printStackTrace();
}
what i expect :
{
"senderId":"XYZ",
"User_Type":"student",
"Text_message":"jgz ",
"studData": [{
"Stud_ID":"100S1000","Mobile_No":"123456789"
},
{
"Stud_ID":"100S1010","Mobile_No":"321654987"
}]
}
what i am getting:
{
"senderId":"XYZ",
"User_Type":"student",
"Text_message":"jgz ",
"studData": [{
"Stud_ID":"100S1000","Mobile_No":"123456789"
},
{
"Stud_ID":"100S1000","Mobile_No":"123456789"
}]
}
question from:https://stackoverflow.com/questions/66058552/i-want-to-put-jsonobject-into-jsonarray-inside-for-loop