最新消息:20210816 当前crifan.com域名已被污染,为防止失联,请关注(页面右下角的)公众号

【已解决】go语言中的字典类型变量:map

GO crifan 3356浏览 0评论

【背景】

折腾:

【记录】用go语言实现模拟登陆百度

期间,需要去实现go语言中的字典类型的变量,以便去存放对应的http的post data。

【折腾过程】

1.之前是学习了:

https://gobyexample.com/

中的:

https://gobyexample.com/maps

所以,知道了go中map就是python语言中的dict。

2.所以直接去写代码,如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
 
postDict := map[string]string{}
//postDict["ppui_logintime"] = ""
postDict["charset"] = "utf-8"
//postDict["codestring"] = ""
postDict["token"] = strLoginToken
postDict["isPhone"] = "false"
postDict["index"] = "0"
//postDict["u"] = ""
//postDict["safeflg"] = "0"
postDict["staticpage"] = staticPageUrl
postDict["loginType"] = "1"
postDict["tpl"] = "mn"
postDict["callback"] = "parent.bdPass.api.login._postCallback"
gLogger.Info("postDict=%s", postDict)

即可实现对应的效果了。

输出为:

1
[2013/09/21 16:06:28 ] [INFO] (main.main:287) postDict=map[charset:utf-8 token:71e32be5d105bc579c8acfe21da7361e isPhone:false index:0 staticpage:http://www.baidu.com/cache/user/html/jump.html loginType:1 tpl:mn callback:parent.bdPass.api.login._postCallback]

【总结】

go语言中的dict字典类型变量,就是map。

对应初始化可以写为:

1
postDict := map[string]string{}

后续直接赋值:

1
postDict["charset"] = "utf-8"

即可。

转载请注明:在路上 » 【已解决】go语言中的字典类型变量:map

发表我的评论
取消评论

表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址
82 queries in 0.494 seconds, using 22.15MB memory