Python和Vend JSON查询

2024-09-29 00:12:22 发布

您现在位置:Python中文网/ 问答频道 /正文

只是想弄清楚我从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”,但似乎还没有完全解决。在

我的代码:

^{pr2}$

如果我可以“遍历”JSON输出,隔离相关字段,那将是非常好的代码。在


Tags: 代码apijsonfieldsizecustompagecode
1条回答
网友
1楼 · 发布于 2024-09-29 00:12:22

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

{
    '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条目并对其进行迭代:

^{pr2}$

相关问题 更多 >