Din*_*lam 2 dictionary go
我需要使用map创建一个JSON数组.
package main
import "fmt"
func main(){
id := [5]string{"1","2","3","4","5"}
name := [5]string{"A","B","C","D","E"}
parseData := make(map[string]string)
for counter,_ := range id {
parseData["id"] = id[counter]
parseData["name"] = name[counter]
fmt.Println(parseData)
}
}
我目前的输出:
map[id:1 name:A]
map[id:2 name:B]
map[id:3 name:C]
map[id:4 name:D]
map[id:5 name:E]
我需要一个JSON输出,如下所示:
[{id:1, name:A},
{id:2, name:B},
{id:3, name:C},
{id:4, name:D},
{id:5, name:E}]
我知道使用map的基础知识是一个用于key:value对的字典.如何使用map实现JSON输出.