微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

从 XHR-response 在 Python 中展平 json

如何解决从 XHR-response 在 Python 中展平 json

更新:之前的 XHR 响应不正确

我未能以正确的方式从 XHR 响应中展平我的 json。 我刚刚扩展了下面的一项,以使其更具可读性。

我正在使用 python 并尝试过,但结果不正确。

u = "URL"
SE_units = requests.get(u,headers=h).json()
dp = pd.json_normalize(SE_units,[SE_units,"Items"])
SE_dp_list.append(dp)

从下面的 XHR-Response 中,我想将 Items-information 转换为 CSV,但是当我执行 export.to_CSV 时,我发现它没有正确展平

{"Content":{
"PaginationCount":12,"FilterValues":null,"Items":
[{
    "Id":258370,"OriginalType":"BostadobjectPage","PublishDate":null,"Title":"02 Skogsvagen","Image":
    {
        "description":null,"alt":null,"externalUrl":"/abc.jpg"
    },"StaticMapImage":null,"Url":"/abcd/","HideReadMore":false,"ProjectData":null,"ObjectData":
    {
        "BuildingTypeLabel":"Rad-/Kedje-/Parhus","ObjectStatus":"SalesInProgress","ObjectStatusLabel":"Till salu","ObjectNumber":"02","City":"staden","RoomInterval":"2-3","LivingArea":"101","SalesPrice":"2 150 000","MonthlyFee":null,"Elevator":false,"Balcony":false,"Terrace":true
    },"FastighetProjectData":null,"FastighetobjectData":null,"OfficeData":null
},{
    "Id":258372,....."same structure as above"
    "OfficeData":null
}],"noresultsMessage":null,"SimplifiedBuildingType":null,"NextIndex":-1,"TotalCount":12,"heading":null,"ShowMoreLabel":null,"DataColumns":null,"Error":null},"ObjectSearchData":
{
    "BuildingVariantId":"Houses","BuildingsFoundLabel":" {count}","BuildingTypeIds":[400],"BuildingsAvailableForSale":12,"BuildingnoresultsLabel":""
}

}

写入 CSV 后的预期输出格式

enter image description here

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。