Three-dimensional magnetic field structure of a flux-emerging region in the solar atmosphere