gpt4 book ai didi

ios - Stripe STPCustomerDeserializer 无法解析客户 Swift

转载 作者:行者123 更新时间:2023-11-29 05:43:08 24 4
gpt4 key购买 nike

从 Stripe API 返回的客户 JSON 无法使用 STPCustomerDeserializer(jsonResponse: data) 进行解析,在定位“id”字段时返回 nil。记录数据显示 id 不为零。

客户对象的格式与 Stripe API 返回的格式完全相同。错误消息“来自 Stripe 的响应无法解析为有效的 JSON。”

调试解串器显示它在此处失败:

// required fields
NSString *stripeId = [dict stp_stringForKey:@"id"];
if (!stripeId) {
return nil; <<< returning here
}

在>>>

- (nullable NSString *)stp_stringForKey:(NSString *)key {
id value = self[key];
if (value && [value isKindOfClass:[NSString class]]) {
return value;
}
return nil; << returning here
}

我尝试以不同的格式传递客户数据,但没有成功。

我看到有人在这里问了类似的问题The data could not be read because it isn't in the correct format JSON & SWIFT 3

["customer": {
"account_balance" = 0;
address = "<null>";
balance = 0;
created = ***;
currency = "<null>";
"default_source" = “***”;
delinquent = 0;
description = "<null>";
discount = "<null>";
email = “***”;
id = "cus_***";
"invoice_prefix" = ***;
"invoice_settings" = {
"custom_fields" = "<null>";
"default_payment_method" = "<null>";
footer = "<null>";
};
livemode = 1;
metadata = {
};
name = "<null>";
object = customer;
phone = "<null>";
"preferred_locales" = (
);
shipping = "<null>";
sources = {
data = (
{
"address_city" = "<null>";
"address_country" = GB;
"address_line1" = "<null>";
"address_line1_check" = "<null>";
"address_line2" = "<null>";
"address_state" = "<null>";
"address_zip" = "<null>";
"address_zip_check" = "<null>";
brand = Visa;
country = GB;
customer = "cus_***";
"cvc_check" = pass;
"dynamic_last4" = "<null>";
"exp_month" = ***;
"exp_year" = ***;
fingerprint = ***;
funding = debit;
id = "card_***";
last4 = ***;
metadata = {
};
name = "<null>";
object = card;
"tokenization_method" = "<null>";
}
);
"has_more" = 0;
object = list;
"total_count" = 1;
url = "/v1/customers/cus_***/sources";
};
subscriptions = {
data = (
);
"has_more" = 0;
object = list;
"total_count" = 0;
url = "/v1/customers/cus_***/subscriptions";
};
"tax_exempt" = none;
"tax_ids" = {
data = (
);
"has_more" = 0;
object = list;
"total_count" = 0;
url = "/v1/customers/cus_***/tax_ids";
};
"tax_info" = "<null>";
"tax_info_verification" = "<null>";
}]

最佳答案

我已经解决了类似的问题,这种情况下的错误似乎是找不到 key 。尝试将模型中的变量设置为可选(?)。如果它没有值,它将返回 nil 或关联的值。

您确定您提到的 id 是 NSString,请尝试使用 NSInteger 或其他数据类型。

关于ios - Stripe STPCustomerDeserializer 无法解析客户 Swift,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56378176/

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