Golang map转换为json

m :=map[string]string{"type":"10","msg":"hello."}
mjson,_ :=json.Marshal(m)
mString :=string(mjson)
fmt.Printf("print mString:%s",mString)

在Api接口项目调用

res,err := DB().Query("select count(id) as idd,member_sex from party_member_info group by member_sex")
	fmt.Println("返回结果集:", res)
	fmt.Println("错误:", err)
	fmt.Println(res[0]["idd"],res[0]["member_sex"])
	fmt.Println(res[1]["idd"],res[1]["member_sex"])
	fmt.Println("map长度:",len(res))

	//m :=map[string]string{"type":"10","msg":"hello."}
	mjson,_ :=json.Marshal(res)
	mString :=string(mjson)
	fmt.Printf("print mString:%s",mString)

你可能感兴趣的:(Golang map转换为json)