Python和Vend JSON查询

Python和Vend JSON查询,python,json,python-2.7,Python,Json,Python 2.7,我只是想了解一下我从Vend JSON API获得的JSON输出: Item pagination Item {u'pages': 10, u'results': 487, u'page_size': 50, u'page': 1} Item customers Item [{u'custom_field_3': u'', u'customer_code': u'WALKIN', u'custom_field_1': u'', u'balance': u'0', u'customer_group

我只是想了解一下我从Vend JSON API获得的JSON输出:

Item pagination
Item {u'pages': 10, u'results': 487, u'page_size': 50, u'page': 1}
Item customers
Item [{u'custom_field_3': u'', u'customer_code': u'WALKIN', u'custom_field_1': u'', u'balance': u'0', u'customer_group_id': u'xxx', u'custom_field_2': u'',
这就是一个例子

我试图从JSON输出中分离一些字段,例如“customer_code”,但似乎还没有完全解决

我的代码:

response = requests.get('http://xxx.vendhq.com/api/customers',
                     auth=('xxx', 'yyy'))

data = response.json()

for item in data.items():
    print 'Item', item[0]
    print 'Item', item[1]

如果我能“漫游”JSON输出,隔离相关字段,那将是非常好的代码。

根据输出和给定的代码,数据结构是:

{
    'pagination': {u'pages': 10, u'results': 487, u'page_size': 50, u'page': 1}
    'customers': [{u'custom_field_3': u'', u'customer_code': u'WALKIN',
                   u'custom_field_1': u'', u'balance': u'0',
                   u'customer_group_id': u'xxx', u'custom_field_2': u'', ..]
}

要获取客户代码列表,您需要使用键
customers
访问dict条目并对其进行迭代:

customer_codes = [customer['customer_code'] for customer in data['customers']]

您最好包括
打印(数据)
的输出。程序的输出使您很难理解JSON的结构。