从Stripe API返回的客户JSON无法通过使用STPCustomerDeserializer(jsonResponse:data)进行解析,在找到“ id”字段时返回nil。记录数据表明id不为零。
customer对象的格式与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>";
}]
答案 0 :(得分:0)
我已经解决了类似的问题,这种情况下的错误似乎是找不到密钥。尝试将模型中的变量设为可选变量(?)。如果该变量没有值,则将返回nil或关联的值。
确定您提到的ID是NSString,请尝试使用NSInteger或其他DataType。
答案 1 :(得分:0)
我修复了!我只需要使用data["customer"]
作为Any
下标到json。