代码改变世界

python json.loads()字符串转json

2023-11-08 22:51  清风软件测试开发  阅读(71)  评论(0编辑  收藏  举报

python  json.loads()字符串转json

import json
import requests

res = '''{"code":200,"message":"success","duration":147,"result":{"angle":0,"height":368,"tables":[],"width":500},"version":"v2.0.0"}'''
json_obj = json.loads(res)
print(type(json_obj))
print(json_obj['result'])
print(json_obj['result']['height'])



url = "https://www.ycpai.cn/other/AddVisit.do"
res = requests.get(url)
print(type(res))
print(res.text)
print(type(res.text))
json_obj = json.loads(res.text)
print(json_obj)
print(type(json_obj))
print(json_obj['resultCode'])



json_string = '{"key1":"value1","key2":"value2","key3":"value3"}'
data = json.loads(json_string)
for key in data:
value = data[key]
print(f"key:{key}, value:{value}")