在Python中从JSON响应中提取数据并排除特定数据

在Python中从JSON响应中提取数据并排除特定数据,python,json,python-2.7,Python,Json,Python 2.7,我的Python shell中有以下json_数据: [{u'alt_name': u'JON~1.EXT', u'attributes': [u'DIRECTORY'], u'create_time': 1538729344, u'filename': u'Jon.Doe', u'last_access_time': 1539071386, u'last_write_time': 1539071386, u'size': 0}, {u'attributes': [u'READONLY', u

我的Python shell中有以下json_数据:

[{u'alt_name': u'JON~1.EXT',
u'attributes': [u'DIRECTORY'],
u'create_time': 1538729344,
u'filename': u'Jon.Doe',
u'last_access_time': 1539071386,
u'last_write_time': 1539071386,
u'size': 0},

{u'attributes': [u'READONLY', u'DIRECTORY'],
u'create_time': 1536996830,
u'filename': u'Public',
u'last_access_time': 1538765229,
u'last_write_time': 1538765229,
u'size': 0},

{u'alt_name': u'ABC_IN~1',
u'attributes': [u'DIRECTORY'],
u'create_time': 1538729345,
u'filename': u'abc_inventory',
u'last_access_time': 1538729531,
u'last_write_time': 1538729531,
u'size': 0}]
我只对“文件名”感兴趣,我想排除“公共”

目标:
乔恩·多伊
美国广播公司库存

提前感谢您的帮助

试试这个:

json_data = [
     {u'alt_name': u'JON~1.EXT',
      u'attributes': [u'DIRECTORY'],
      u'create_time': 1538729344,
      u'filename': u'Jon.Doe',
      u'last_access_time': 1539071386,
      u'last_write_time': 1539071386,
      u'size': 0},

     {u'attributes': [u'READONLY', u'DIRECTORY'],
      u'create_time': 1536996830,
      u'filename': u'Public',
      u'last_access_time': 1538765229,
      u'last_write_time': 1538765229,
      u'size': 0},

     {u'alt_name': u'ABC_IN~1',
      u'attributes': [u'DIRECTORY'],
      u'create_time': 1538729345,
      u'filename': u'abc_inventory',
      u'last_access_time': 1538729531,
      u'last_write_time': 1538729531,
      u'size': 0}]


filenames = [i['filename'] for i in json_data]
输出将是:

['Jon.Doe', 'Public', 'abc_inventory']
['Jon.Doe', 'abc_inventory']
如果逻辑是不获取
公共

filenames = [i['filename'] for i in json_data if i['filename'] !='Public']
输出将是:

['Jon.Doe', 'Public', 'abc_inventory']
['Jon.Doe', 'abc_inventory']

filenames=[i['filename']表示json_数据中的i,如果i['filename']!='Public']