示例#1
0
func ExampleDictFromMap() {
	d2, _ := lich.DictFromMap(map[string]interface{}{
		"greeting": map[string]interface{}{
			"English":  []byte{72, 101, 108, 108, 111},
			"Japanese": "Konnichiwa",
		},
		"fruit":          []string{"apple", "banana", "orange"},
		"selling points": lich.ArrayFromStrings("simple", "general", "human-sympathetic"),
	})
	fmt.Println(d2)
	//Output: 158{5<fruit>26[5<apple>6<banana>6<orange>]8<greeting>43{7<English>5<Hello>8<Japanese>10<Konnichiwa>}14<selling points>40[6<simple>7<general>17<human-sympathetic>]}

}
示例#2
0
func TestInvalidMap(t *testing.T) {
	d2, err := lich.DictFromMap(map[string]interface{}{
		"greeting": map[string]interface{}{
			"English":  []byte{72, 101, 108, 108, 111},
			"Japanese": "Konnichiwa",
			"Dog":      9.0,
		},
		"fruit":          []string{"apple", "banana", "orange"},
		"selling points": lich.ArrayFromStrings("simple", "general", "human-sympathetic"),
	})
	if (err != lich.UnknownTypeError{"Dog", 9.0}) {
		t.Fatal(d2, err)
	}
}