Question #251

Author: admin
tags: Go  
JSON string is 100% correct:
package main

import (
	"encoding/json"
	"fmt"
)

func main() {
	jsonStr := `
		{
			"title": "Supaplex",
			"year": 1991
		}
	`

	var parsedData any

	json.Unmarshal([]byte(jsonStr), &parsedData)

	if dataMap, ok := parsedData.(map[string]any); ok {
		if title, ok := dataMap["title"].(string); ok {
			fmt.Println(title)
		}

		if year, ok := dataMap["year"].(int); ok {
			fmt.Println(year)
		}
	}
}
What will be printed?
Nothing
Supaplex and 1991
Supaplex
1991
The code will not be compiled
Unmarshal() maps JSON numbers into float64 Go values.
Rate the difficulty of the question:
easyhard