1,json.loads (字符串转换成Python对象)
2,json.dumps(Python对象转换成字符串)
3,json.load() 读取json文件内容转换为Python类型
例如:
import json
strList = json.load(open("listStr.json"))
4,json.dump() 将Python内置类型序列化为json对象写入文件
例如:
import json
listStr = [{"city": "北京"}]
json.dump(listStr, open("listStr.json", "w"), ensure_ascii=False)
jsonPath是一种信息抽取类库,是从json文档中抽取指定信息的工具,提供多种语言实现版本,包括: Javascript, Python,PHP和Java
安装方法: pipenv install jsonpath
官网地址: http://goessner.net/articles/JsonPath

jsonpath的使用
拉勾网json 信息
import requests
import json
from jsonpath import jsonpath
url = "https://www.lagou.com/lbs/getAllCitySearchLabels.json"
headers = {
'User-Agent': "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_5) "
"AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3770.100 Safari/537.36"
}
res = requests.get(url, headers=headers)
python_res = json.loads(res.text)
# print(python_res)
name = jsonpath(python_res, '$..name')
print('---', name)
浙公网安备 33010602011771号