Ad

How To Covert A Custom Class Into Json Array Or Json Dictionary In Objective C?

- 1 answer

Hi I'm using mobile buy sdk for my eCommerce app.After login I try to save Customer in model manager by using the following code

    [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"];
                }
            }];

My problem is BuyCustomer is a class i have to convert it into either JsonArray or JsonDictionary so then only I can able to save it. How can I convert BuyCustomer class into either one of above and save it? Thanks in advance.

Ad

Answer

if you have customer logged in you can use following code to get customer

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

                    if (error) {

                        NSLog(@"Customer error");

                    }else{

                        NSLog(@"Customer available");

                        self.customer = _customer;

                    }

                }];
Ad
source: stackoverflow.com
Ad