Growing evidence indicates that the synchrotron radiation mechanism may be responsible for the prompt emission of gamma-ray bursts (GRBs). In the synchrotron radiation scenario, the electron energy spectrum of the prompt emission is diverse in theoretical works and has not been estimated from observations in a general way (i.e., without specifying a certain physical model for the electron spectrum). In this paper, we creatively propose a method to directly estimate the electron spectrum for the prompt emission, without specifying a certain physical model for the electron spectrum in the synchrotron radiation scenario. In this method, an empirical function (i.e., a four-order Bezier curve jointed with a linear function at high-energy) is applied to describe the electron spectrum in log-log coordinate. It is found that our empirical function can well mimic the electron spectra obtained in many numerical calculations or simulations. Then, our method can figure out the electron spectrum for the prompt emission without specifying a model. By employing our method on observations, taking GRB 180720B and GRB 160509A as examples, it is found that the obtained electron spectra are generally different from that in the standard fast-cooling scenario and even a broken power law. Moreover, the morphology of electron spectra in its low-energy regime varies with time in a burst and even in a pulse. Our proposed method provides a valuable way to confront the synchrotron radiation mechanism with observations.