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; }
}
}
- 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.
- Kindly share us the issue reproducing sample.
- Does the issue is thrown at grid initial rendering or while doing any grid actions?
- Share us the video demo of the problem you are facing.
- 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.
- I have just upgrade from 19.2.0.49 to 19.2.0.60 and the problem was not solved
- Kindly share us the issue reproducing sample.
- I am sharing the main pages where I got the problem
- Does the issue is thrown at grid initial rendering or while doing any grid actions?
- 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.
- Share us the video demo of the problem you are facing.
- video is attached.
Thank you.
Leo
Attachment: Error_95856641.rar
|
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;
}
}
|
Thank you Jeevakanth .
It is working.
Best regards,
Leo
- 5 Replies
- 2 Participants
-
LR Leo Ramos
- Sep 9, 2021 03:04 PM UTC
- Sep 14, 2021 05:33 AM UTC