2
我有我想要打印的JSON輸出是這個樣子的Python腳本:漂亮打印JSON
{
"authMode": "open",
"enabled": false,
"ipAssignmentMode": "NAT mode",
"name": "Unconfigured SSID 14",
"number": 13,
"perClientBandwidthLimitDown": 0,
"perClientBandwidthLimitUp": 0,
"splashPage": "None",
"ssidAdminAccessible": false
},
{
"authMode": "open",
"enabled": false,
"ipAssignmentMode": "NAT mode",
"name": "Unconfigured SSID 15",
"number": 14,
"perClientBandwidthLimitDown": 0,
"perClientBandwidthLimitUp": 0,
"splashPage": "None",
"ssidAdminAccessible": false
}
但我的輸出看起來像這個:
{u'authMode': u'open',
u'enabled': False,
u'ipAssignmentMode': u'NAT mode',
u'name': u'Unconfigured SSID 14',
u'number': 13,
u'perClientBandwidthLimitDown': 0,
u'perClientBandwidthLimitUp': 0,
u'splashPage': u'None',
u'ssidAdminAccessible': False},
{u'authMode': u'open',
u'enabled': False,
u'ipAssignmentMode': u'NAT mode',
u'name': u'Unconfigured SSID 15',
u'number': 14,
u'perClientBandwidthLimitDown': 0,
u'perClientBandwidthLimitUp': 0,
u'splashPage': u'None',
u'ssidAdminAccessible': False}]
我覺得有一些簡單的我錯過了。這裏是我的代碼:
url = "https://dashboard.meraki.com/api/v0/networks/%s/ssids" % NETWORKID
headers = {'X-Cisco-Meraki-API-Key': APIKEY}
r = requests.get(url, headers=headers, allow_redirects=True)
pprint (r.json())
您正在使用'pprint',一個基本上將數據序列化回原生Python語法的模塊。如果可能的話,使用常規的'print'將會輸出一個字符串的值。如果你想把json數據作爲一個字符串來使用,我認爲你需要'r.body',我認爲'r.json'是解碼值,例如,它已經被轉換爲本地python類型。 – ThorSummoner