我正在使用python进行一个项目,其中我使用请求从REST API获取json,然后继续将其加载到PostgreSQL数据库中。API 响应的 json 的结构如下所示。我的主要问题是关于嵌套字段,如和嵌套在数组中的字段,如.location.latinfoinfo[0].value
{
"items": [
{
"id": 300436,
"item_id_parent": null,
"reference": "",
"subreference1": "CAMS\/1",
"subreference2": "CAMS\/1",
"reference_alpha": null,
"reference_numeric": null,
"oid": "CAMS\/1",
"code": null,
"code_custom": null,
"name": "284",
"image": "https:\/\/static.inventsys.com.br\/278\/thumb\/f-3298886-200x200c.jpg",
"situations": [],
"project_id": 10762,
"project": {
"id": 10762,
"name": "Fauna EGR",
"color": null
},
"category_id": 20685,
"category": {
"id": 20685,
"name": "EGR FAUNA - Armadilhas"
},
"area_id": null,
"area": null,
"location": {
"lat": -30.136699676514,
"lng": -50.910511016846,
"address": {
"region": "RS",
"city": "Viamão",
"district": null,
"zipcode": null,
"street": "Rodovia Tapir Rocha",
"street_number": null,
"desc": null,
"full": "Rodovia Tapir Rocha Viamão \/ BR"
}
},
这里的问题是,如果我只使用前四个变量运行代码,它工作正常,所以我想当涉及到我想要解析的嵌套字段时,我的语法都是错误的。如何最好地引用这些字段?
提前感谢大家!
MYYA
相关分类