You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何处理二维Python列表的方括号以适配Firebase RTDB数据结构

问题:Firebase RTDB 上传天气数据时列表导致额外节点问题

我开发了一个获取天气数据的基础网络爬虫,需要将数据上传至Firebase实时数据库(RTDB)。当前数据存储在二维列表中便于处理,但Python列表的方括号会使Firebase RTDB在JSON树中生成额外节点。

当前数据结构(Python列表)

[{'Weather Data': [{'Houston': {'weather': 'Chance of showers', 'uvindex': '0', 'category': 'Low', 'timeabove': 'None'}}, {'Seattle': {'weather': 'Chance of showers', 'uvindex': '3', 'category': 'Moderate', 'timeabove': '1 pm to  2 pm'}}]}]

期望的Firebase RTDB结构

Weather Data
    Houston
       weather: Chance of showers
       uvindex: 0
       category: Low
       timeabove: None
    Seattle
       weather: Chance of showers
       uvindex: 3
       category: Moderate
       timeabove: 1 pm to 2 pm

实际生成的Firebase RTDB结构

0
   Weather Data
       0
         Houston
            weather: Chance of showers
            uvindex: 0
            category: Low
            timeabove: None
       1
         Seattle
            weather: Chance of showers
            uvindex: 3
            category: Moderate
            timeabove: 1 pm to 2 pm

经测试确认是列表的方括号导致生成这些额外的数字节点。我想了解:

  • 是否有Firebase端的格式适配方案可以避免这种情况?
  • 或者Python中有没有现成的函数,能将这类嵌套列表转换为简洁的JSON格式(无需逐个手动提取子列表)?

内容的提问来源于stack exchange,提问作者lookout-four

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.10 03:35:07