获取所需的JSON路径可以通过以下步骤进行:
以下是一个示例,假设我们有以下JSON数据:
{
"employees": [
{
"firstName": "John",
"lastName": "Doe"
},
{
"firstName": "Jane",
"lastName": "Smith"
}
]
}
如果我们想获取第二个员工的姓氏("Smith"),可以按照以下步骤进行:
import json
json_data = '''
{
"employees": [
{
"firstName": "John",
"lastName": "Doe"
},
{
"firstName": "Jane",
"lastName": "Smith"
}
]
}
'''
data = json.loads(json_data)
json_path = "employees[1].lastName"
last_name = data["employees"][1]["lastName"]
print(last_name) # 输出:Smith
腾讯云相关产品和产品介绍链接地址:
领取专属 10元无门槛券
手把手带您无忧上云