python json转json string
时间: 2023-09-11 20:12:55 浏览: 155
要将Python对象转换为JSON字符串,可以使用json.dumps()方法。例如,假设有一个名为data的Python对象,可以使用以下代码将其转换为JSON字符串:
```python
import json
data = {'name': 'Tom', 'age': 18}
json_str = json.dumps(data)
print(json_str)
```
这将输出JSON字符串`{"name": "Tom", "age": 18}`。<em>1</em><em>2</em><em>3</em>
#### 引用[.reference_title]
- *1* *2* [python str如何转json](https://blog.csdn.net/qq_27487739/article/details/131144801)[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^chatsearchT0_1"}} ] [.reference_item]
- *3* [python json string和dict的转化](https://blog.csdn.net/w36680130/article/details/103557763)[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^chatsearchT0_1"}} ] [.reference_item]
[ .reference_list ]