【背景】
折腾:
期间,需要去实现go语言中的字典类型的变量,以便去存放对应的http的post data。
【折腾过程】
1.之前是学习了:
中的:
所以,知道了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