We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

JSON object deserialize

Hi.

I am trying to bind data on the sfgrid from a webapi that returns a Json as you can see below, but the component is returning the flowing error: Newtonsoft.Json.JsonSerializationException: Cannot deserialize the current JSON array (e.g. [1,2,3]) into type 'Syncfusion.Blazor.Data.OData`1[HPReconnectV3.Data.VendorContractMarkups]' because the type requires a JSON object (e.g. {"name":"value"}) to deserialize correctly.  


The code I am using:

<SfGrid TValue="VendorContractMarkups " AllowResizing="true">

    <GridEvents TValue="VendorContractMarkups" OnActionFailure="@ActionFailure"></GridEvents>

    <SfDataManager Url="https://localhost:44325/api/VendorContractMarkup?MemberId=1566&VendorProductId=421275" CrossDomain="true" Adaptor="Adaptors.ODataAdaptor"></SfDataManager>


    <GridPageSettings PageSize="10"></GridPageSettings>


    <GridColumns>

        <GridColumn Field="@nameof(VendorContractMarkups.Distributor)" HeaderText="Distributor" TextAlign="@TextAlign.Left" Width="200"> </GridColumn>

        <GridColumn Field="@nameof(VendorContractMarkups.Warehouse)" HeaderText="Warehouse" TextAlign="@TextAlign.Left" Width="190"> </GridColumn>

        <GridColumn Field="@nameof(VendorContractMarkups.ProductCode)" HeaderText="Product Code" TextAlign="@TextAlign.Left" Width="80"> </GridColumn>

        <GridColumn Field="@nameof(VendorContractMarkups.Markup)" HeaderText="Markup %" TextAlign="@TextAlign.Left" Width="80"> </GridColumn>

        <GridColumn Field="@nameof(VendorContractMarkups.FinalPrice)" HeaderText="Final Price" Format="C2" TextAlign="@TextAlign.Left" Width="80"> </GridColumn>

        <GridColumn Field="@nameof(VendorContractMarkups.NextPrice)" HeaderText="Next Price" Format="C2" TextAlign="@TextAlign.Left" Width="80"> </GridColumn>

        <GridColumn Field="@nameof(VendorContractMarkups.NextPriceDate)" HeaderText="Next Price Date" TextAlign="@TextAlign.Left" Width="80"> </GridColumn>

    </GridColumns>

</SfGrid>



@code {

.....


    private SfGrid<VendorContractMarkups> PriceGrid;

    IEnumerable<VendorContractMarkups> vendorcontractmarkups;


 public class VendorContractMarkups

    {

        public string Distributor { get; set; }

        public string Warehouse { get; set; }

        public string ProductCode { get; set; }

        private float _markup;

        public Nullable<float> Markup

        {

            get

            {

                if (_markup != 0)

                    return _markup;

                else

                    return null;

            }

            set

            {

                _markup = (float)value;

            }

        }


        private float _finalprice;

        public Nullable<float> FinalPrice

        {


            get

            {

                if (_finalprice != 0)

                    return _finalprice;

                else

                    return null;

            }

            set

            {

                _finalprice = (float)value;

            }

        }

        private float _nextprice;

        public Nullable<float> NextPrice

        {


            get

            {

                if (_nextprice != 0)

                    return _nextprice;

                else

                    return null;

            }

            set

            {

                _nextprice = (float)value;

            }



        }

        public string NextPriceDate { get; set; }


    }


}



5 Replies

JP Jeevakanth Palaniappan Syncfusion Team September 10, 2021 10:33 AM UTC

Hi Leo, 

Greetings from Syncfusion support. 

We have checked your query but we need more details to proceed further on this. So kindly share the below information, 

  1. Share us the Syncfusion NuGet version details. Also if you are using older version then kindly check the problem whether is get resolved in the latest Syncfusion NuGet version.
  2. Kindly share us the issue reproducing sample.
  3. Does the issue is thrown at grid initial rendering or while doing any grid actions?
  4. Share us the video demo of the problem you are facing.

The above requested details will be helpful for us to validate your query and to provide you with a better solution as early as possible. 

Regards, 
Jeevakanth SP. 



LR Leo Ramos September 10, 2021 04:15 PM UTC

  1. Share us the Syncfusion NuGet version details. Also if you are using older version then kindly check the problem whether is get resolved in the latest Syncfusion NuGet version.
    1. I have just upgrade from 19.2.0.49 to 19.2.0.60 and the problem was not solved

  1. Kindly share us the issue reproducing sample.
    1. I am sharing the main pages where I got the problem
  2. Does the issue is thrown at grid initial rendering or while doing any grid actions?
    1. Both. The goal is to be part of an hierarchical grid and load when the user expand the line. Due to the problem I extract the grid and added it at the initial rendering. I also copied a sample from Syncfusion pages to load at the initial rendering and comparer. The sample pull data from another web API. Both API returns JSON patterns. The sample grid is working as you can see in the video.
  3. Share us the video demo of the problem you are facing.
    1. video is attached.


Thank you. 


Leo


Attachment: Error_95856641.rar


JP Jeevakanth Palaniappan Syncfusion Team September 13, 2021 02:20 PM UTC

Hi Leo, 

Thanks for sharing the requested details. 

We have analyzed your code and found that you are using WebAPI adaptor and we suspect that you have not returned the WebAPI response properly which is the cause of the issue. For the WebAPI to work properly, the response object should be in the form of Items and Count. We have prepared a sample to use the WebAPI adaptor. Please refer it below sample, documentation and the screenshot for your reference. 



 

DefaultController.cs 
public async Task<object> Get(int? code){ 
.. 
            var queryString = Request.Query; 
            if (queryString.Keys.Contains("$inlinecount")) 
            { 
                StringValues Skip; 
                StringValues Take; 
                int skip = (queryString.TryGetValue("$skip", out Skip)) ? Convert.ToInt32(Skip[0]) : 0; 
                int top = (queryString.TryGetValue("$top", out Take)) ? Convert.ToInt32(Take[0]) : data.Count(); 
 
               var count = data.Count();                                 
                    return new { Items = data.Skip(skip).Take(top), Count = count };                 
            } 
            else 
            { 
                return data; 
            } 
} 


Incase if you are still facing the reported problem then kindly reproduce the issue in the above provided sample which will be helpful for us to validate your query and to provide you with a  better solution as early as possible. 

Regards, 
Jeevakanth SP. 




LR Leo Ramos September 13, 2021 09:10 PM UTC

Thank you  Jeevakanth .


It is working.


Best regards,


Leo



JP Jeevakanth Palaniappan Syncfusion Team September 14, 2021 05:33 AM UTC

Hi Leo, 

We are glad that the provided solution resolved the reported problem. Get back to us if you have any other queries. 

Regards, 
Jeevakanth SP. 


Loader.
Live Chat Icon For mobile
Up arrow icon