Python JSON Vend API定义

时间:2014-09-25 06:20:38

标签: python regex json

我有这段代码:

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

customer_groups = [customer['customer_group_name'] for customer in data['customers']]

我可以做得更好吗?

完整JSON结构的示例输出(来自Vend文档):

{
"customers": [
{
    "id": "18a68b58-ccd7-11df-a32f-4040f540b50a",
    "name": "Bob smith",
    "customer_code": "Bob-U2K9",
    "updated_at": "2010-09-30 20:52:51",
    "deleted_at": "",
    "balance": "0.00000",
    "year_to_date": "0.00000",
    "points": "0",
    "customer_group_id": "6e1dee9e-80e4-11df-b0bf-4040f540b50a",
    "customer_group_name": "All Customers",
    "company_name": "Bob’s company",
    "phone": "555-1235",
    "mobile": "",
    "fax": "",
    "email": "",
    "website": "",
    "physical_address1": "",
    "physical_address2": "",
    "physical_suburb": "",
    "physical_city": "",
    "physical_postcode": "",
    "physical_state": "",
    "physical_country_id": "",
    "postal_address1": "",
    "postal_address2": "",
    "postal_suburb": "",
    "postal_city": "",
    "postal_postcode": "",
    "postal_state": "",
    "postal_country_id": "US"
}]

}

我的代码生成其中一个字段的输出:

[u'All Customers', u'Annual Members', u'All Customers']

如果我要提及"名字"我会以此为例:

[u'Customer 1', u'Customer 2', u'Customer 3']

我需要获取该格式的Vend示例数据,而不是我获取的数据。这将允许我对已经存在于SQL数据库中的记录中的JSON数据进行正则表达式搜索()。

非常感谢!

0 个答案:

没有答案