zzss 发表于 2017-7-9 06:55:48

江湖小妞

import json  In : obj = """{"name":"Wes", "places_lived":["United States", "Spain", "Germany"], "pet":nu
  ...: ll, "siblings":[{"name":"Scott","age":25,"pet":"Zuko"},{"name":"Katy","age":33,"pet":"
  ...: Cisco"}]}"""
  In : res = json.loads(obj) # 将JSON字符串转换为Python形式
  In : res
  Out:
  {u'name': u'Wes',
  u'pet': None,
  u'places_lived': ,
  u'siblings': [{u'age': 25, u'name': u'Scott', u'pet': u'Zuko'},
  {u'age': 33, u'name': u'Katy', u'pet': u'Cisco'}]}
  # 将Python转换为json
  In : asjson = json.dumps(res)
  In : asjson
  Out: '{"pet": null, "siblings": [{"pet": "Zuko", "age": 25, "name": "Scott"}, {"pet": "Cisco", "age": 33, "name": "Katy"}], "name": "Wes", "places_lived": ["United States", "Spain", "Germany"]}'
  In[]: data = DataFrame(res['siblings'], columns=['name', 'age'])
  In : data
  Out:
  nameage
  0Scott   25
  1   Katy   33
页: [1]
查看完整版本: 江湖小妞