str1:="平安银行,12.250,12.450,12.350"str2:="name,open,close,down"小弟刚刚入手golang,求问下有两个字符串str1,str2想合并并转换成如下格式,请问该如何操作?感激不尽{"name":"平安银行","open":"12.250","close":"12.450","down":"12.350"}
2 回答
GCT1015
TA贡献1827条经验 获得超4个赞
packagemainimport("encoding/json""fmt""strings")funcmain(){str1:="平安银行,12.250,12.450,12.350"str2:="name,open,close,down"sep:=","s1:=strings.Split(str1,sep)s2:=strings.Split(str2,sep)iflen(s1)!=len(s2){return}m:=make(map[string]string)fori,v:=ranges2{m[v]=s1[i]}result,err:=json.Marshal(m)fmt.Printf("结果:%s,错误:%v\n",result,err)}
添加回答
举报
0/150
提交
取消