Javascript 尝试使用带有JSON的点表示法从条带API获取特定键值时遇到问题
我正在从测试发票中提取条带API中的数据。我试图缩小范围,使用点表示法提取特定的键值对,但从特定的键值提取数据时遇到了问题,因为它似乎比其他数据更深(不确定这是否是正确的术语) 我试图从中提取数据的数据来自Javascript 尝试使用带有JSON的点表示法从条带API获取特定键值时遇到问题,javascript,json,stripe-payments,Javascript,Json,Stripe Payments,我正在从测试发票中提取条带API中的数据。我试图缩小范围,使用点表示法提取特定的键值对,但从特定的键值提取数据时遇到了问题,因为它似乎比其他数据更深(不确定这是否是正确的术语) 我试图从中提取数据的数据来自period:end:和period:start:大致来自第44-46行 如果我在代码中使用点表示法,则当键值对位于同一行时,如sheet.getRange(3,2).setValue([content.amount_due])。但“period:end”和“period:start”似乎嵌套
period:end:
和period:start:
大致来自第44-46行
如果我在代码中使用点表示法,则当键值对位于同一行时,如sheet.getRange(3,2).setValue([content.amount_due])代码>。但“period:end”和“period:start”似乎嵌套得更深
我试着做一些类似于[content.lines.data.period.end]
的事情,但没有成功。它返回以下错误:TypeError:无法从未定义的中读取属性“end”。
以下是从API中提取的完整数据(注意:“xxxxxxxxxxxxxx”
表示隐藏的数据):
数据是一个数组,请尝试content.lines.data[0].period.end
以防万一。
""id"": ""in_xxxxxxxxxxxxxxxx"",
""object"": ""invoice"",
""amount_due"": 800,
""amount_paid"": 800,
""amount_remaining"": 0,
""application_fee"": null,
""attempt_count"": 1,
""attempted"": true,
""auto_advance"": false,
""billing"": ""charge_automatically"",
""billing_reason"": ""subscription_cycle"",
""charge"": ""ch_xxxxxxxxxxxxxxxx"",
""closed"": true,
""created"": 1552077120,
""currency"": ""usd"",
""custom_fields"": null,
""customer"": ""cus_xxxxxxxxxxxxxxxx"",
""date"": 1552077120,
""default_payment_method"": null,
""default_source"": null,
""description"": null,
""discount"": null,
""due_date"": null,
""ending_balance"": 0,
""finalized_at"": 1552080770,
""footer"": null,
""forgiven"": false,
""hosted_invoice_url"": ""https://pay.stripe.com/invoice/invst_xxxxxxxxxxxxxxxx"",
""invoice_pdf"": ""https://pay.stripe.com/invoice/invst_xxxxxxxxxxxxxxxx/pdf"",
""lines"": {
""object"": ""list"",
""data"": [
{
""id"": ""sub_xxxxxxxxxxxxxxxx"",
""object"": ""line_item"",
""amount"": 800,
""currency"": ""usd"",
""description"": null,
""discountable"": true,
""livemode"": false,
""metadata"": {
},
""period"": {
""end"": 1554755515,
""start"": 1552077115
},
""plan"": {
""id"": ""xxxxxxxxxxxxxxxx"",
""object"": ""plan"",
""active"": true,
""aggregate_usage"": null,
""amount"": 400,
""billing_scheme"": ""per_unit"",
""created"": 1407529859,
""currency"": ""usd"",
""interval"": ""month"",
""interval_count"": 1,
""livemode"": false,
""metadata"": {
},
""name"": ""sdf"",
""nickname"": null,
""product"": ""prod_xxxxxxxxxxxxxxxx"",
""statement_description"": null,
""statement_descriptor"": null,
""tiers"": null,
""tiers_mode"": null,
""transform_usage"": null,
""trial_period_days"": null,
""usage_type"": ""licensed""
},
""proration"": false,
""quantity"": 2,
""subscription"": null,
""subscription_item"": ""si_xxxxxxxxxxxxxxxx"",
""type"": ""subscription"",
""unique_line_item_id"": ""sli_xxxxxxxxxxxxxxx""
}
],
""has_more"": false,
""total_count"": 1,
""url"": ""/v1/invoices/in_xxxxxxxxxxxxxxxx/lines""
},
""livemode"": false,
""metadata"": {
},
""next_payment_attempt"": null,
""number"": ""77E3C02-0025"",
""paid"": true,
""payment"": ""ch_1xxxxxxxxxxxxxxxx"",
""payment_intent"": ""pi_xxxxxxxxxxxxxxxx"",
""period_end"": 1552077115,
""period_start"": 1549657915,
""receipt_number"": ""2258-2679"",
""starting_balance"": 0,
""statement_description"": null,
""statement_descriptor"": null,
""status"": ""paid"",
""status_transitions"": {
""finalized_at"": 1552080770,
""marked_uncollectible_at"": null,
""paid_at"": 1552080772,
""voided_at"": null
},
""subscription"": ""sub_xxxxxxxxxxxxxxxx"",
""subtotal"": 800,
""tax"": null,
""tax_percent"": null,
""total"": 800,
""webhooks_delivered_at"": 1552077123
}"```
[1]: https://stripe.com/docs/api/invoices/retrieve