如何处理二维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
相关产品推荐
相关产品推荐

