encoding/json: fix panics on type mismatches.

Fixes issue 4222.
Fixes issue 4628.

R=golang-dev, adg
CC=golang-dev
https://codereview.appspot.com/7100049