Recovering the Hamiltonian from spectral data