you first declare arrays :
String[] name ={"yousuf" , "Mohammed" , "Ali" , "Hamood" , "Alex"};
String[] emails = {"yousuf@dd" , "Mohammed@dd" , "Ali@dd" , "Hamood@dd" , "Alex@dd"};
any arrays with data ,
then you create JSONArray
JSONArray array = new JSONArray();
then you make loop to add objects to the array :
for (int i =0; (i < name.length) && (i < emails.length) ; i++ ) {
JSONObject object = new JSONObject();
try {
object.put("name", name[i]);
object.put("email" , emails[i]);
array.put(object);
}catch (JSONException e) {
e.printStackTrace();
}
}
then you can print the results in the console :
Log.d("Json is " , array.toString());
you will get the result like this :
[{"name":"yousuf","email":"yousuf@dd"},{"name":"Mohammed","email":"Mohammed@dd"},{"name":"Ali","email":"Ali@dd"},{"name":"Hamood","email":"Hamood@dd"},{"name":"Alex","email":"Alex@dd"}]
but you can format it by :
Json formatter and validator
and you'll have nice look to the data :

here is the whole code:
public void getDataInJsonFormat (){
String[] name ={"yousuf" , "Mohammed" , "Ali" , "Hamood" , "Alex"};
String[] emails = {"yousuf@dd" , "Mohammed@dd" , "Ali@dd" , "Hamood@dd" , "Alex@dd"};
JSONArray array = new JSONArray();
for (int i =0; (i < name.length) && (i < emails.length) ; i++ ) {
JSONObject object = new JSONObject();
try {
object.put("name", name[i]);
object.put("email" , emails[i]);
array.put(object);
}catch (JSONException e) {
e.printStackTrace();
}
}
Log.d("Json is " , array.toString());
}