gpt4 book ai didi

python - Stripe : How to convert stripe model object into JSON to get complete hierarchical data?

转载 作者:行者123 更新时间:2023-12-05 08:08:09 25 4
gpt4 key购买 nike

如何将 strip 模型对象转换为JSON,以便在客户端接收完整的分层数据?

stripeCustomer = stripe.Customer.retrieve(<stripe customer id>)
sendResponseToClient(stripeCustomer)

我在客户端仅接收 json 形式的第一级数据,来自 Stripe JSON 对象的第二级数据未格式化。

JSON 数据示例:(客户端未收到第 2 级数据,)

 Customer customer id=cus_DTWEPsfrHx3ikZ at 0x00000a> JSON: {
"id": "cus_DTWEPsfrHx3ikZ",
"object": "customer",
"account_balance": 0,
"created": 1535093686,
"currency": "usd",
"default_source": null,
"delinquent": false,
"description": null,
"discount": null,
"email": "rakesh16+test9@gmail.com",
"invoice_prefix": "E91FF30",
"livemode": false,
"metadata": {
},
"shipping": null,
"sources": {
"object": "list",
"data": [

],
"has_more": false,
"total_count": 0,
"url": "/v1/customers/cus_DTWEPsfrHx3ikZ/sources"
},
"subscriptions": {
"object": "list",
"data": [
{
"id": "sub_DTWEALN3urFael",
"object": "subscription",
"application_fee_percent": null,
"billing": "charge_automatically",
"billing_cycle_anchor": 1535093688,
"cancel_at_period_end": false,
"canceled_at": null,
"created": 1535093688,
"current_period_end": 1537772088,
"current_period_start": 1535093688,
"customer": "cus_DTWEPsfrHx3ikZ",
"days_until_due": null,
"discount": null,
"ended_at": null,
"items": {
"object": "list",
"data": [
{
"id": "si_DTWEuZaU4pw9Cv",
"object": "subscription_item",
"created": 1535093688,
"metadata": {
},
"plan": {
"id": "plan_free",
"object": "plan",
"active": true,
"aggregate_usage": null,
"amount": 0,
"billing_scheme": "per_unit",
"created": 1535008667,
"currency": "usd",
"interval": "month",
"interval_count": 1,
"livemode": false,
"metadata": {
},
"nickname": "free",
"product": "prod_DT8B8auk3CRNdw",
"tiers": null,
"tiers_mode": null,
"transform_usage": null,
"trial_period_days": null,
"usage_type": "licensed"
},
"quantity": 1,
"subscription": "sub_DTWEALN3urFael"
}
],
"has_more": false,
"total_count": 1,
"url": "/v1/subscription_items?subscription=sub_DTWEALN3urFael"
},
"livemode": false,
"metadata": {
},
"plan": {
"id": "plan_free",
"object": "plan",
"active": true,
"aggregate_usage": null,
"amount": 0,
"billing_scheme": "per_unit",
"created": 1535008667,
"currency": "usd",
"interval": "month",
"interval_count": 1,
"livemode": false,
"metadata": {
},
"nickname": "free",
"product": "prod_DT8B8auk3CRNdw",
"tiers": null,
"tiers_mode": null,
"transform_usage": null,
"trial_period_days": null,
"usage_type": "licensed"
},
"quantity": 1,
"start": 1535093688,
"status": "active",
"tax_percent": null,
"trial_end": null,
"trial_start": null
}
],
"has_more": false,
"total_count": 1,
"url": "/v1/customers/cus_DTWEPsfrHx3ikZ/subscriptions"
},
"tax_info": null,
"tax_info_verification": null
}

最佳答案

您可以使用以下技术将返回的 Stripe 对象模型转换为 JSON 以忽略不可序列化的字段:

stripeObject = stripe.SomeAPICall(...)
jsonEncoded = json.dumps(stripeObject, default=lambda o: '<not serializable>')
pythonDict = json.loads(jsonEncoded)

关于python - Stripe : How to convert stripe model object into JSON to get complete hierarchical data?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52043797/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com