将Json在线解码为Python中的字符串

时间:2018-03-04 21:25:12

标签: python json decode

我想解码这个json https://deathsnacks.com/wf/data/voidtraders.json

[{u'Node': u'Kronia Relay (Saturn)', u'NodeIndex': 0, u'ManifestIndex': 0, u'Manifest': None, u'Activation': {u'usec': 0, u'sec': 1520604000}, u'Character': u"Baro'Ki Teel", u'Expiry': {u'usec': 0, u'sec': 1520773200}, u'_id': {u'id': u'5967933ca351963d1cd7faa5'}, u'Config': None, u'NextRotation': None}]

使用Python并获得这样的回复

Node: Kronia Relay (Saturn)
Activation: X min
Character: Baro'Ki Teel
Expiry: X min

等等

1 个答案:

答案 0 :(得分:0)

import requests, json, pprint
r = requests.get('https://deathsnacks.com/wf/data/voidtraders.json').text
data = json.loads(r)
pprint.pprint(data)

[{'Activation': {'sec': 1520604000, 'usec': 0},
  'Character': "Baro'Ki Teel",
  'Config': None,
  'Expiry': {'sec': 1520773200, 'usec': 0},
  'Manifest': None,
  'ManifestIndex': 0,
  'NextRotation': None,
  'Node': 'Kronia Relay (Saturn)',
  'NodeIndex': 0,
  '_id': {'id': '5967933ca351963d1cd7faa5'}}]

您还可以遍历字典项:

for key,value in data.items():
    print('{}: {}'.format(key, value))