How to create JSON Array and JSON Object for the same key but different value in android?

How can I create a JSON with this format in Android:

  {
      "update":[
         "key":"headache",
         "value":false,
         "key:":"soreThroat",
         "value":false,
         "key":"nose,color",
         "value":["yellow","white"],
         "key":"urine,color',
         "value":["none"] 
  }

what I know is only the JSONObject. Like this one:

 for(int i=0; i < xxxx ; i++){
       object.put("key", key);
       if(value is Boolean){
         object.put("value",value[i]);
       }else if (value is JSONArray){
         for (int int j=0; j < xxxx; j++){
           object.put("value",value[j]);
         }
       }
  }

Any ideas,Thank.

Answer

You could use below code to achieve your requirement.

            try {

            JSONObject rootJson = new JSONObject();
            JSONObject first = new JSONObject();
            first.put("key","headache");
            first.put("value",false);
            JSONObject second = new JSONObject();
            second.put("key","soreThroat");
            second.put("value",true);
            JSONArray firstArray = new JSONArray().put("yellow");
            firstArray.put("white");
            JSONArray secondArray = new JSONArray().put("urine");
            secondArray.put("color");

            JSONObject firstArrayJson = new JSONObject();
            firstArrayJson.put("key",firstArray);
            JSONObject secondArrayJson = new JSONObject();
            secondArrayJson.put("key",secondArray);

            JSONArray jsonArray = new JSONArray();
            jsonArray.put(first);
            jsonArray.put(second);
            jsonArray.put(firstArrayJson);
            jsonArray.put(secondArrayJson);
            rootJson.put("update",jsonArray);
            Log.d("TAG==", "JSON==>> "+rootJson);
        }catch (JSONException jsonException) {
            jsonException.printStackTrace();
        }