Click here to Skip to main content
15,897,273 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
my json format is like
..................
{
"template": {
"section": "Total",
"totalRecievedTillDate": null,
"receivedFiles": "0",
"attendedFiles": "0",
"pendingFiles": "0",
"totalActionPendingTillDate": null,
"totalActionCompletedTappal": null,
"last15DaysActionCompleted": null,
"last15DaysRecievedTappal": null
},
"sectiontappals": [
{
"section": "Collectorate-A Section",
"totalRecievedTillDate": null,
"receivedFiles": "0",
"attendedFiles": "0",
"pendingFiles": "0",
"totalActionPendingTillDate": null,
"totalActionCompletedTappal": null,
"last15DaysActionCompleted": null,
"last15DaysRecievedTappal": null
},
{
"section": "Collectorate-B Section",
"totalRecievedTillDate": null,
"receivedFiles": "0",
"attendedFiles": "0",
"pendingFiles": "0",
"totalActionPendingTillDate": null,
"totalActionCompletedTappal": null,
"last15DaysActionCompleted": null,
"last15DaysRecievedTappal": null
},
{
"section": "Collectorate-C Section",
"totalRecievedTillDate": null,
"receivedFiles": "0",
"attendedFiles": "0",
"pendingFiles": "0",
"totalActionPendingTillDate": null,
"totalActionCompletedTappal": null,
"last15DaysActionCompleted": null,
"last15DaysRecievedTappal": null
},
{
"section": "Collectorate-D Section",
"totalRecievedTillDate": null,
"receivedFiles": "0",
"attendedFiles": "0",
"pendingFiles": "0",
"totalActionPendingTillDate": null,
"totalActionCompletedTappal": null,
"last15DaysActionCompleted": null,
"last15DaysRecievedTappal": null
},
{
"section": "Collectorate-E Section",
"totalRecievedTillDate": null,
"receivedFiles": "0",
"attendedFiles": "0",
"pendingFiles": "0",
"totalActionPendingTillDate": null,
"totalActionCompletedTappal": null,
"last15DaysActionCompleted": null,
"last15DaysRecievedTappal": null
},
{
"section": "Collectorate-F and G Section",
"totalRecievedTillDate": null,
"receivedFiles": "0",
"attendedFiles": "0",
"pendingFiles": "0",
"totalActionPendingTillDate": null,
"totalActionCompletedTappal": null,
"last15DaysActionCompleted": null,
"last15DaysRecievedTappal": null
},
{
"section": "Collectorate-H Section",
"totalRecievedTillDate": null,
"receivedFiles": "0",
"attendedFiles": "0",
"pendingFiles": "0",
"totalActionPendingTillDate": null,
"totalActionCompletedTappal": null,
"last15DaysActionCompleted": null,
"last15DaysRecievedTappal": null
},
{
"section": "Collectorate-IAP Section",
"totalRecievedTillDate": null,
"receivedFiles": "0",
"attendedFiles": "0",
"pendingFiles": "0",
"totalActionPendingTillDate": null,
"totalActionCompletedTappal": null,
"last15DaysActionCompleted": null,
"last15DaysRecievedTappal": null
},
{
"section": "Collectorate-LC Section",
"totalRecievedTillDate": null,
"receivedFiles": "0",
"attendedFiles": "0",
"pendingFiles": "0",
"totalActionPendingTillDate": null,
"totalActionCompletedTappal": null,
"last15DaysActionCompleted": null,
"last15DaysRecievedTappal": null
},
{
"section": "Collectorate-LP Section",
"totalRecievedTillDate": null,
"receivedFiles": "0",
"attendedFiles": "0",
"pendingFiles": "0",
"totalActionPendingTillDate": null,
"totalActionCompletedTappal": null,
"last15DaysActionCompleted": null,
"last15DaysRecievedTappal": null
},
{
"section": "Collectorate-LR Section",
"totalRecievedTillDate": null,
"receivedFiles": "0",
"attendedFiles": "0",
"pendingFiles": "0",
"totalActionPendingTillDate": null,
"totalActionCompletedTappal": null,
"last15DaysActionCompleted": null,
"last15DaysRecievedTappal": null
},
{
"section": "None",
"totalRecievedTillDate": null,
"receivedFiles": "0",
"attendedFiles": "0",
"pendingFiles": "0",
"totalActionPendingTillDate": null,
"totalActionCompletedTappal": null,
"last15DaysActionCompleted": null,
"last15DaysRecievedTappal": null
}
]
}
...............

i want to bind this to my datagrid view.i couldnt do. pls help

i want columns like :section, totalRecievedTillDate,receivedFiles,attendedFiles,pendingFiles,totalActionPendingTillDate,totalActionCompletedTappal,last15DaysActionCompleted,last15DaysRecievedTappal

What I have tried:

using (WebClient wc = new WebClient())
{
var json = wc.DownloadString("URL");
var user = JsonConvert.DeserializeObject<List<clsdashbord>>(json);

datagrid1.DataSource = user;
}
Posted
Updated 14-Apr-20 5:27am
v5

You first need to deserialise the JSON into C# objects, see How to: Serialize and Deserialize JSON Data[^]. Once you have the data in a usable form you can bind the resulting content to your DataGridView.
 
Share this answer
 
Comments
NarasinghRao 6-Feb-17 6:20am    
not getting data
Richard MacCutchan 6-Feb-17 6:29am    
Is that supposed to mean something?
NarasinghRao 6-Feb-17 6:42am    
it shows like: Cannot deserialize the current JSON object (e.g. {"name":"value"}) into type 'System.Collections.Generic.List`1[dashboard.clsdashbord]' because the type requires a JSON array (e.g. [1,2,3]) to deserialize correctly.

To fix this error either change the JSON to a JSON array (e.g. [1,2,3]) or change the deserialized type so that it is a normal .NET type (e.g. not a primitive type
Richard MacCutchan 6-Feb-17 7:02am    
It looks like you are trying to deserialize the wrong part of the returned JSON. The section beginning at sectiontappals is a JSON array, but it is not clear what is before that.
NarasinghRao 6-Feb-17 7:06am    
ok.can i bind data from sectiontappals. is it possible ? if yes. pls tell me Sir
{ "totalCount": 2,
"limit": 100,
"offset": 0,
"pageCount": 1,
"items": [
{
"dueDate": "2019-01-18T00:00:00",
"lastStatusUpdateDate": "2019-01-16T16:34:47",
"id": "b17553de-db34-49ed-99ac-7382291fa7bd",
"sku": "HBV000007NVPO",
"orderId": "a9965c83-085f-4130-8809-5acb4070da5d",
"orderNumber": "0874654893",
"orderDate": "2019-01-16T16:34:47",
"quantity": 1,
"merchantId": "823539cd-1f10-4971-8859-cd648cfb4ff6",
"totalPrice": {
"currency": "TRY",
"amount": 301.4
},
"unitPrice": {
"currency": "TRY",
"amount": 301.4
},
"hbDiscount": {
"totalPrice": {
"currency": "TRY",
"amount": 0
},
"unitPrice": {
"currency": "TRY",
"amount": 0
}
},
"vat": 0,
"vatRate": 0,
"customerName": "Emre Test",
"status": "Open",
"shippingAddress": null,
"invoice": {
"turkishIdentityNumber": "1234567890",
"taxNumber": "12345",
"taxOffice": "Ýstanbul",
"address": {
"addressId": "e66765b3-d37d-488c-ae15-47051245dc9b",
"address": "Trump Towers",
"name": "Hepsiburada Office",
"email": "customer@hepsiburada.com.tr",
"countryCode": "TR",
"phoneNumber": "902822613231",
"alternatePhoneNumber": "045321538212",
"district": "Sisli",
"city": "İstanbul",
"town": null
}
},
"sapNumber": "12345",
"dispatchTime": 1,
"commission": {
"currency": "TRY",
"amount": 1
},
"paymentTermInDays": 30,
"commissionType": 0,
"cargoCompanyModel": {
"id": 1,
"name": "Yurtiçi Kargo",
"shortName": "YK",
"logoUrl": "http://images.hepsiburada.com/assets/cargo-logo/yurtici.svg",
"trackingUrl": "http://selfservis.yurticikargo.com/reports/SSWDocumentDetail.aspx?DocId={0}"
},
"cargoCompany": "Yurtiçi Kargo",
"customizedText01": null,
"customizedText02": null,
"customizedText03": null,
"customizedText04": null,
"customizedTextX": null,
"creditCardHolderName": null,
"isCustomized": false,
"canCreatePackage": true,
"isCancellable": true,
"isCancellableByHbAdmin": true,
"deliveryType": "StandardDelivery",
"deliveryOptionId": 1,
"slot": {
"id": null,
"timeslot": "14:00-16:00"
},
"pickUpTime": null
},
{
"dueDate": "2019-01-18T00:00:00",
"lastStatusUpdateDate": "2019-01-16T16:34:47",
"id": "82c41b2b-e30b-4d38-9162-1aeae7eadecc",
"sku": "HBV00000DBR6S",
"orderId": "a9965c83-085f-4130-8809-5acb4070da5d",
"orderNumber": "0874654893",
"orderDate": "2019-01-16T16:34:47",
"quantity": 2,
"merchantId": "823539cd-1f10-4971-8859-cd648cfb4ff6",
"totalPrice": {
"currency": "TRY",
"amount": 610.8
},
"unitPrice": {
"currency": "TRY",
"amount": 305.4
},
"hbDiscount": {
"totalPrice": {
"currency": "TRY",
"amount": 0
},
"unitPrice": {
"currency": "TRY",
"amount": 0
}
},
"vat": 0,
"vatRate": 0,
"customerName": "Emre Test",
"status": "Open",
"shippingAddress": null,
"invoice": {
"turkishIdentityNumber": "1234567890",
"taxNumber": "12345",
"taxOffice": "Ýstanbul",
"address": {
"addressId": "e66765b3-d37d-488c-ae15-47051245dc9b",
"address": "Trump Towers",
"name": "Hepsiburada Office",
"email": "customer@hepsiburada.com.tr",
"countryCode": "TR",
"phoneNumber": "902822613231",
"alternatePhoneNumber": "045321538212",
"district": "Sisli",
"city": "İstanbul",
"town": null
}
},
"sapNumber": "12345",
"dispatchTime": 1,
"commission": {
"currency": "TRY",
"amount": 1
},
"paymentTermInDays": 30,
"commissionType": 0,
"cargoCompanyModel": {
"id": 1,
"name": "Yurtiçi Kargo",
"shortName": "YK",
"logoUrl": "http://images.hepsiburada.com/assets/cargo-logo/yurtici.svg",
"trackingUrl": "http://selfservis.yurticikargo.com/reports/SSWDocumentDetail.aspx?DocId={0}"
},
"cargoCompany": "Yurtiçi Kargo",
"customizedText01": null,
"customizedText02": null,
"customizedText03": null,
"customizedText04": null,
"customizedTextX": null,
"creditCardHolderName": null,
"isCustomized": false,
"canCreatePackage": true,
"isCancellable": true,
"isCancellableByHbAdmin": true,
"deliveryType": "StandardDelivery",
"deliveryOptionId": 1,
"slot": {
"id": null,
"timeslot": "14:00-16:00"
},
"pickUpTime": null
}
]
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900