简体   繁体   English

使用Python解析Firebase JSON

[英]Parsing Firebase JSON with Python

I'm working with the following JSON structures 我正在使用以下JSON结构

{
    "-L6Tr0Wl5fuG3tDgUPCa": {
        "List": "{'x': [0.02245, 0.02196], 'y': [0.96941, 0.97014], 'z': [0.05344, 0.05368]}",
        "Index": "17361"
    },
    "-L6Tr4j05NV6BJKcaRSe": {
        "List": "{'x': [0.03196, 0.01537], 'y': [0.96795, 0.96966], 'z': [0.05051, 0.04929]}",
        "Index": "17362"
    }
}

The name of each entry is random (eg L6Tr0Wl5fuG3tDgUPCa) that is generated by firebase whenever we push a new entry. 每个条目的名称都是随机的(例如L6Tr0Wl5fuG3tDgUPCa),它是由Firebase在每次推送新条目时生成的。 What is the best way to parse and iterate through each entry of such a JSON file in python? 在python中这种JSON文件的每个条目中解析和迭代的最佳方法是什么?

The file is huge with a couple of thousands of such entries. 该文件很大,有成千上万个这样的条目。

I've never done Python before, but this seems to work in https://www.python.org/shell/ : 我以前从未做过Python,但这似乎可以在https://www.python.org/shell/中使用

import json
data = {
    "-L6Tr0Wl5fuG3tDgUPCa": {
        "List": "{'x': [0.02245, 0.02196], 'y': [0.96941, 0.97014], 'z': [0.05344, 0.05368]}",
        "Index": "17361"
    },
    "-L6Tr4j05NV6BJKcaRSe": {
        "List": "{'x': [0.03196, 0.01537], 'y': [0.96795, 0.96966], 'z': [0.05051, 0.04929]}",
        "Index": "17362"
    }
}

for key in data:
  print(key, data[key])

Also see: 另请参阅:

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM