pythondumps函数用法
时间: 2023-10-14 21:00:46 浏览: 109
Python函数的运用方法
引用中提到了json.dumps()函数的用法。json.dumps()函数是将数据类型字典/列表转化为数据类型字符串。具体使用方法如下:
import json
dict_data = {'name':'张三', 'age':18, 'hobby':{'hobby1':'打游戏', 'gender':['1','2']}}
str_data = json.dumps(dict_data)
print(str_data)
# 输出结果: {"name": "张三", "age": 18, "hobby": {"hobby1": "打游戏", "gender": ["1", "2"]}}
在这个例子中,我们定义了一个字典dict_data,然后使用json.dumps()函数将字典转化为字符串str_data。最后,我们打印出str_data的值,可以看到字典被转化为了对应的字符串形式。<span class="em">1</span><span class="em">2</span><span class="em">3</span>
#### 引用[.reference_title]
- *1* *2* [python教程:Json模块中dumps、dump、loads、load函数用法讲解](https://blog.csdn.net/qdPython/article/details/123923738)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"]
- *3* [Python中的dump() 、load()和dumps()、loads()使用及示例](https://blog.csdn.net/qq_42898701/article/details/128076021)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"]
[ .reference_list ]
阅读全文