python json字符串转json对象
时间: 2023-10-11 16:13:17 浏览: 267
要在Python中将JSON字符串转换为JSON对象,可以使用json模块的loads()函数。以下是一个示例代码:
```python
import json
json_str = '{"name":"blue","age":"20"}'
json_obj = json.loads(json_str)
print(json_obj)
print(json_obj['name'])
print(json_obj['age'])
```
这段代码首先导入了json模块,然后使用loads()函数将JSON字符串转换为JSON对象。然后,可以像操作字典一样,通过键访问JSON对象中的值。在这个例子中,我们打印了整个JSON对象以及"name"和"age"字段的值。<span class="em">1</span><span class="em">2</span><span class="em">3</span>
#### 引用[.reference_title]
- *1* *2* [【学习笔记】【python】json字符串与json对象相互转换](https://blog.csdn.net/lvchengfeng1992/article/details/105847089)[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 style="max-width: 50%"]
- *3* [如何将 Python 字符串转换为 JSON](https://blog.csdn.net/pythondby/article/details/121904578)[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 style="max-width: 50%"]
[ .reference_list ]
阅读全文