Python JSON供应商API定义
我有以下代码:Python JSON供应商API定义,python,regex,json,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']] 我能做得更好吗 Vend docs完整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']]
我能做得更好吗
Vend docs完整JSON结构的输出示例:
{
"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数据进行正则表达式搜索
非常感谢 你谈论SQL之类的东西,但它似乎与你的实际问题无关。你能澄清你真正想要的是什么吗,最好是去掉那些不相关的部分?我也不知道为什么你给我们的代码在顶部;这似乎也不是问题的一部分。请展示一个没有字段提取的原始JSON结构的摘录,以及您希望获得的数据结构的示例。还要注意,Python列表不是链表。我将在Python中定义一个链表,根据:。顶部的代码是为了查看JSON的来源——我能做得更好吗?我确实在谈论SQL,因为我需要将这些数据从JSON插入SQL中——我知道如何做,我所需要做的就是将其转换为一种可以插入的格式。显然,我不能只是向您展示机密的客户数据,所以需要虚拟数据。此外,这是我从程序中获得的确切输出,除了机密名称的审查。有关完整结构,请参阅:。