如何在 objective c 中将自定义 class 转换为 json 数组或 json 字典?

How to covert a custom class into json array or json dictionary in objective c?

你好我正在为我的电子商务使用移动购买 sdk app.After 登录我尝试使用以下代码在模型管理器中保存客户

    [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 是 class 我必须将其转换为 JsonArray 或 JsonDictionary,这样我才能保存它。我怎样才能将 BuyCustomer class 转换为上述任何一种并保存?提前致谢。

如果您有客户登录,您可以使用以下代码获取客户

[self.client getCustomerCallback:^(BUYCustomer * _Nullable _customer, NSError * _Nullable error) {

                    if (error) {

                        NSLog(@"Customer error");

                    }else{

                        NSLog(@"Customer available");

                        self.customer = _customer;

                    }

                }];