DeserializeObject using C# library data contract into AX 2012 X++

public void getCustomers()
{

    InteropPermission               permission;
    System.Exception                clrException;
    str response;
    int64 _shopifyCustomerId;
    CustTable _custtable;

    DirParty                        _dirParty;
    System.Collections.IEnumerator  lEnum;
    System.Collections.IEnumerator  addressListEnum;

    Newtonsoft.Json.Linq.JObject    jObject;
    Newtonsoft.Json.Linq.JObject    addressjObject;

    Newtonsoft.Json.Linq.JArray     list = new Newtonsoft.Json.Linq.JArray();

    _customerService = new ETTCShopifyServiceLibrary.Service.CustomerService();
     _customer= new ETTCShopifyServiceLibrary.Models.ViewModel.CustomerMainVM();

    _addressVM= new ETTCShopifyServiceLibrary.Models.ViewModel.Address() ;
     _defualtAddress= new ETTCShopifyServiceLibrary.Models.ViewModel.DefaultAddress();
     _addressList = new System.Collections.ArrayList();

    response=  _customerService.getCustomers();
      try
    {
        permission = new InteropPermission(InteropKind::ClrInterop);
        permission.assert();

        list = Newtonsoft.Json.JsonConvert::DeserializeObject(response, list.GetType());
        lEnum = list.GetEnumerator();

        while (lEnum.MoveNext())
        {
             jObject = lEnum.get_Current();
            _customer = Newtonsoft.Json.JsonConvert::DeserializeObject(jObject.ToString(), _customer.GetType());
            _shopifyCustomerId = _customer.get_Id();

            select firstOnly _custtable where _custtable.BIShopifyCustomerId ==_shopifyCustomerId;
            // check if this customer exist
            if(! _custtable.RecId)
            {
                _dirParty= this.CreateCustomer(_customer);
            _addressList = _customer.get_Addresses();
            addressListEnum = _addressList.GetEnumerator();

             while (addressListEnum.MoveNext())
                  {
                       addressjObject = addressListEnum.get_Current();
                        _addressVM = Newtonsoft.Json.JsonConvert::DeserializeObject(addressjObject.ToString(), _addressVM.GetType());
                        this.CreateAddress(_addressVM, _dirParty,_customer);

                  }
            this.ContactInfo( _dirParty,_customer);
            }

        }
    }
    catch (Exception::CLRError)
    {
        warning("Error");
    }

}

https://threads1701.rssing.com/chan-54662410/article144102.html

Leave Comment

Your email address will not be published. Required fields are marked *