1、{"key1":"value1","key2":"value2"}转key1=value1;key2=value2
# json 转 cookies参数
def jsonDataToCookiesParams(params_data):
strParams = ""
nums = 0
max_nums = len(params_data)
for key in params_data:
nums = nums + 1
# 如果是最后一位就不要带上,
# 拼为字符串
if nums == max_nums:
strParams += str(key) + '=' + str(params_data[key])
else:
strParams += str(key) + '=' + str(params_data[key]) + ';'
return str(strParams)
2、{"key1":"value1","key2":"value2"}转key1=value1&key2=value2
# json 转 geturlparams参数
def jsonDataToCookiesParams(params_data):
strParams = ""
nums = 0
max_nums = len(params_data)
for key in params_data:
nums = nums + 1
# 如果是最后一位就不要带上,
# 拼为字符串
if nums == max_nums:
strParams += str(key) + '=' + str(params_data[key])
else:
strParams += str(key) + '=' + str(params_data[key]) + '&'
return str(strParams)