Unmarshalling JSON with Key Names Containing Spaces
You're encountering an issue where spaces in JSON key names are causing problems during unmarshalling using the encoding/json library. Specifically, the library removes spaces from the key names in the schema, leading to confusion and incorrect unmarshalling.
Solution
The error lies in your incorrect JSON tag specification. In your example:
The tag for Name has a leading space before the colon, which is incorrect. It should be:
There shouldn't be a space after the colon in the tag specification. With this correction, the unmarshalling will work as expected, and you'll be able to access key names with spaces in your JSON data.
The above is the detailed content of How to Unmarshal JSON with Spaces in Key Names?. For more information, please follow other related articles on the PHP Chinese website!