How to input text from edit text in json array
yes you can , on button click you have to retrieve all values from editext , make a jsonobject like that
JSONObject student1 = new JSONObject();
try {
student1.put("id", "3");
student1.put("name", "NAME OF STUDENT");
student1.put("year", "3rd");
student1.put("curriculum", "Arts");
student1.put("birthday", "5/5/1993");
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Try it this way:
Before you make a call to the below function, make sure that your edit text does not return null. Use basic validations.
public JSONArray makeJSON() {
JSONArray jArr = new JSONArray();
JSONObject jObj = new JSONObject();
try {
jObj.put("customer_name", edittex1.getText().toString);
jObj.put("serial_number", edittex2.getText().toString);
jObj.put("membership_number", edittex3.getText().toString);
jObj.put("brand_name", edittex4.getText().toString);
jObj.put("model_number", edittex5.getText().toString);
jObj.put("IMEI_number", edittex6.getText().toString);
jObj.put("handset_purchase", edittex7.getText().toString);
jObj.put("counter_name", edittex8.getText().toString);
jArr.put(jObj);
} catch (Exception e) {
System.out.println("Error:" + e);
}
return jArr;
}