# Python处理Json对象
# Python处理Json对象
'''
json.loads() 将JSON字符串转为Python对象
json.dumps() 将Python对象转为JSON字符串
'''
import json
json_str = '{"key1":"value1","key2":"value2","key3":"vlue3"}'
python_dict = json.loads(json_str)
# loads()将json字符串转为Python的字典对象
print(type(python_dict))
print(type(json_str))
项目:Python获取json页面内容,做动态数据分析
# 项目:Python获取json页面内容,做动态数据分析
import request
import json
url = '********************'
response = request.get(url).text() # response.get(url) 返回的是状态码
# 将JSON字符串转为Python对象
python_object = json.loads(response) # 也可以用json(response)
get_books = python_object['key1']
contents = len(get_books) # 分行展示
print(content)