# Python 如何把 String 转换为 Json 对象

**URL:** <https://www.isharkfly.com/t/python-string-json/14977>\
**Category:** Python\
**Tags:** python\
**Created:** [September 19, 2023, 2:29am UTC](https://www.isharkfly.com/t/python-string-json/14977 "2023-09-19T02:29:28Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Lucas-ossez](https://www.isharkfly.com/letter_avatar_proxy/v4/letter/l/8e7dd6/32.png) [@Lucas-ossez](https://www.isharkfly.com/u/Lucas-ossez)\
**Post date:** [September 19, 2023, 2:29am UTC](https://www.isharkfly.com/t/python-string-json/14977/1 "2023-09-19T02:29:28Z")

</div>

在我们对 JSON 进行处理的时候，大概率我们会需要把字符串转换为 JSON 对象后才能进行处理。

Python 贴心的使用

```auto
json.loads(employee_string)

```

就可以了。

首先需要做的就是导入 JSON 库。

`#include json library import json`

对现代程序员来说，JSON 数据结构基本上是非常常见的数据结构了，几乎所有语言都可以处理。

```auto
#include json library
import json

#json string data
employee_string = '{"first_name": "Michael", "last_name": "Rodgers", "department": "Marketing"}'

#check data type with type() method
print(type(employee_string))

#convert string to object
json_object = json.loads(employee_string)

#check new data type
print(type(json_object))

```

上面的代码就可以直接让 Python 把字符串转换为 JSON 的对象了。

 ![](https://cdn.isharkfly.com/com-isharkfly-www/discourse-uploads/original/2X/a/ad9fa29570ebeb2dbba9bec4c2322351f9362916.png)  
当我们完成转换后，就可以对 JSON 的对象进行相关操作了。
