簡體   English   中英

如何使用 python 打印 json 信息?

[英]How to print json info with python?

我有一個 json (url = http://open.data.amsterdam.nl/ivv/parkeren/locaties.json )和我想打印'郵政編碼','所有我怎樣才能做到這一點?

我想像這樣打印它:

title.
adres.
postcode.

title. 
adres. 
postcode.

所以他們之間

這是我的python腳本

我希望你能幫我解決這個問題

 import urllib, json url = "http://open.data.amsterdam.nl/ivv/parkeren/locaties.json" import requests search = requests.get(url).json() print(search['title']) print(search['adres']) print(search['postcode'])

使用print(json.dumps(r, indent=4))你可以看到結構是

{
    "parkeerlocaties": [
        {
            "parkeerlocatie": {
                "title": "Fietsenstalling Tolhuisplein",
                "Locatie": "{\"type\":\"Point\",\"coordinates\":[4.9032801,52.3824545]}",
                 ...
            }
        },
        {
            "parkeerlocatie": {
                "title": "Fietsenstalling Paradiso",
                "Locatie": "{\"type\":\"Point\",\"coordinates\":[4.8833735,52.3621851]}",
                 ...
            }
        },

因此要訪問內部屬性,您需要遵循 JSON 路徑

import requests
url = ' http://open.data.amsterdam.nl/ivv/parkeren/locaties.json'
search = requests.get(url).json()
for parkeerlocatie in search["parkeerlocaties"]:
    content = parkeerlocatie['parkeerlocatie']
    print(content['title'])
    print(content['adres'])
    print(content['postcode'])
    print()

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM