title: Json array to object
body: <p>How can i convert this json array to a json object. And i need to store this json to a remote server. How can i do it. I cannot find a perfect tutorial for this purpose.</p>
  
  <pre><code> private JSONArray getResults() {
  
      String myPath = "/data/data/com.example.sebastian.patientdetails/databases/" + "MyDBName.db";
  
      String myTable = "patients";
  
  
      SQLiteDatabase myDataBase = SQLiteDatabase.openDatabase(myPath, null, SQLiteDatabase.OPEN_READONLY);
  
      String searchQuery = "SELECT  * FROM " + myTable;
      Cursor cursor = myDataBase.rawQuery(searchQuery, null);
  
      JSONArray resultSet = new JSONArray();
  
      cursor.moveToFirst();
      while (!cursor.isAfterLast()) {
  
          int totalColumn = cursor.getColumnCount();
          JSONObject rowObject = new JSONObject();
  
          for (int i = 0; i &lt; totalColumn; i++) {
              if (cursor.getColumnName(i) != null) {
                  try {
                      if (cursor.getString(i) != null) {
                          Log.d("TAG_NAME", cursor.getString(i));
                          rowObject.put(cursor.getColumnName(i), cursor.getString(i));
                      } else {
                          rowObject.put(cursor.getColumnName(i), "");
                      }
                  } catch (Exception e) {
                      Log.d("TAG_NAME", e.getMessage());
                  }
              }
          }
          resultSet.put(rowObject);
          cursor.moveToNext();
      }
      cursor.close();
      Log.d("TAG_NAME", resultSet.toString());
      return resultSet;
  }
  </code></pre>