Structure-preserving Method for Reconstructing Unknown Hamiltonian Systems from Trajectory Data