Improve robustness by improving JSON parsing code

1. Improve robustness by improving JSON parsing code
2. Handle more error situations.