Stripe API与Excel VBA:含子属性的HTTP请求参数语法问题
Stripe API嵌套参数URL拼接语法(Excel VBA场景)
对于Stripe API里的嵌套子属性(比如
custom_fields这类数组/对象型参数),不能直接用点号.拼接,要采用方括号[]嵌套语法:- 如果是数组型参数(比如
custom_fields是一个对象数组),需要通过索引指定数组元素,再嵌套属性名,格式为参数名[索引][子属性名] - 单条自定义字段的示例:
custom_fields[0][name]=会员ID&custom_fields[0][value]=VBA001 - 多条字段就递增索引,比如
custom_fields[1][name]=到期日期&custom_fields[1][value]=2025-12-31
- 如果是数组型参数(比如
结合你之前的URL拼接逻辑,完整的URL示例如下:
Dim fullUrl As String fullUrl = b_url & "/v1/invoices?auto_advance=false&collection_method=charge_automatically&customer=" & customerid & "&custom_fields[0][name]=会员ID&custom_fields[0][value]=VBA001"
注意:建议把参数分隔符从分号
;换成标准的&,虽然Stripe兼容分号,但&是URL参数的通用分隔符,能避免潜在兼容性问题。
- 另外,如果你用VBA发送请求时遇到特殊字符(比如中文、空格),记得用
URLEncode处理参数值,示例代码:
Dim encodedName As String encodedName = WorksheetFunction.EncodeURL("会员ID") Dim encodedValue As String encodedValue = WorksheetFunction.EncodeURL("VBA001") fullUrl = b_url & "/v1/invoices?auto_advance=false&collection_method=charge_automatically&customer=" & customerid & "&custom_fields[0][name]=" & encodedName & "&custom_fields[0][value]=" & encodedValue
内容的提问来源于stack exchange,提问作者user2938667
相关产品推荐
相关产品推荐

