Python Parsen von JSON-array

Ich versuche, um gemeinsam ein kleines python-Skript Parsen kann aus array ' s aus einem großen Datensatz. Ich bin auf der Suche, um zu ziehen ein paar key:values von jedem Objekt so, dass ich spielen kann Sie später wieder auf in der Schrift. Für jetzt möchte ich nur die Ergebnisse gedruckt werden. Ich habe Erfolg gehabt, dies zu tun mit JSON-Dateien, die enthalten nur Objekte, kann aber nicht scheinen, um es arbeiten für ein array. Irgendwelche Tipps würde sehr geschätzt werden

Hier ist mein code:

# Load up JSON Function
import json

# Open our JSON file and load it into python
input_file = open ('stores-small.json')
json_array = json.load(input_file)

# Create a variable that will take JSON and put it into a python dictionary
store_details = [
        ["name"],
        ["city"]
    ]

# Learn how to loop better =/
for stores in [item["store_details"] for item in json_array]

# Print my results
print(store_details)

Hier ist die Beispiel-JSON-Daten:

[
  {
    "id": 1000,
    "type": "BigBox",
    "name": "Mall of America",
    "address": "340 W Market",
    "address2": "",
    "city": "Bloomington",
    "state": "MN",
    "zip": "55425",
    "location": {
      "lat": 44.85466,
      "lon": -93.24565
    },
    "hours": "Mon: 10-9:30; Tue: 10-9:30; Wed: 10-9:30; Thurs: 10-9:30; Fri: 10-9:30; Sat: 10-9:30; Sun: 11-7",
    "services": [
      "Geek Squad Services",
      "Best Buy Mobile",
      "Best Buy For Business"
    ]
  },
  {
    "id": 1002,
    "type": "BigBox",
    "name": "Tempe Marketplace",
    "address": "1900 E Rio Salado Pkwy",
    "address2": "",
    "city": "Tempe",
    "state": "AZ",
    "zip": "85281",
    "location": {
      "lat": 33.430729,
      "lon": -111.89966
    },
    "hours": "Mon: 10-9; Tue: 10-9; Wed: 10-9; Thurs: 10-9; Fri: 10-10; Sat: 10-10; Sun: 10-8",
    "services": [
      "Windows Store",
      "Geek Squad Services",
      "Best Buy Mobile",
      "Best Buy For Business"
    ]}
  ]
InformationsquelleAutor RomeNYRR | 2017-11-01
Schreibe einen Kommentar