您好,我正在为我的电子商务应用程序使用移动购买 SDK。登录后,我尝试使用以下代码将客户保存在模型管理器中
[self.client loginCustomerWithCredentials:credentials callback:^(BUYCustomer * customer, BUYCustomerToken * token, NSError * _Nullable error) {
if (customer && !error) {
[self.client.modelManager insertCustomersWithJSONArray:customer];
[self.client.modelManager insertCustomerWithJSONDictionary:customer];
}else{
[self showEror:@"LogIn Failed" message:@"Please provide valid Details"];
}
}];
我的问题是 BuyCustomer 是一个类,我必须将其转换为 JsonArray 或 JsonDictionary,这样我才能保存它。如何将 BuyCustomer 类转换为上述任一类并保存?提前致谢。
最佳答案
如果您有客户登录,您可以使用以下代码获取客户
[self.client getCustomerCallback:^(BUYCustomer * _Nullable _customer, NSError * _Nullable error) {
if (error) {
NSLog(@"Customer error");
}else{
NSLog(@"Customer available");
self.customer = _customer;
}
}];
关于ios - 如何将自定义类转换为 objective-c 中的 json 数组或 json 字典?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41360959/