How can I represent map[string][]byte?

huangapple go评论78阅读模式
英文:

How can I represent map[string][]byte?

问题

我想创建一个地图,但我不确定语法。map[string][]byte 数据类型给我带来了麻烦,因为我认为下面的示例应该是编译器所期望的样子,但我收到了一个错误消息,对于正确的表示方式并不清楚。

map["k1":[1,2,3] "k2":[4,5,6] "k3":[7,8,9]]

错误消息:

> 期望的类型,找到了 "k1"

我该如何修复语法?

英文:

I would like to create a map, but I am unsure of the syntax. The map[string][]byte data type is giving me trouble, because I think that the example below should be what it should look like in order to appease the compiler, but I receive an error which is unclear about how it should be properly depicted.

map["k1":[1,2,3] "k2":[4,5,6] "k3":[7,8,9]]

The error message:

> expected type, found "k1"

How can I fix the syntax?

答案1

得分: 2

你的语法有问题。
你应该像下面这样初始化和声明:

	x := map[string][]byte{
		"k1": []byte{1, 2, 3},
		"k2": []byte{4, 5, 6},
		"k3": []byte{7, 8, 9},
	}
英文:

You have bad syntax.
You should initialize it and declare like below

	x := map[string][]byte{
		"k1": []byte{1, 2, 3},
		"k2": []byte{4, 5, 6},
		"k3": []byte{7, 8, 9},
	}

huangapple
  • 本文由 发表于 2022年4月24日 00:51:41
  • 转载请务必保留本文链接:https://go.coder-hub.com/71981765.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定