I have the below json response. How to read the CustomerList data from the json response. I will bind this data to a gridview. Using the Newtonsoft.Json nuget.
{
"Status": "OK",
"StatusCode": "200",
"payload":{
"SentItemCount": "65",
"MatchingItemCount": "64",
"CustomerList": [
{
"EntityName": "Franklin LLC",
"EntityID": "06012",
"ContactNum": "913-022-8187"
},
{
"EntityName": "Stanley Firm LLC",
"EntityID": "02398",
"ContactNum": "832-980-2056"
},
{
"EntityName": "Zneith Systems LLC",
"EntityID": "05801",
"ContactNum": "482-120-9406"
}
]
}
}
CodePudding user response:
I don't know what kind of gridview you are using but you can get data from json by 2 ways
using Newtonsoft.Json;
var jsonParsed=JObject.Parse(json);
DataTable dataTable=jsonParsed["payload"]["CustomerList"].ToObject<DataTable>();
// or
List<Customer> customerList=jsonParsed["payload"]["CustomerList"].ToObject<List<Customer>>();
Now you can use or dataTable or customer list as a source to your gridview
if you decided to use a list , you will need to create this class
public class Customer
{
public string EntityName { get; set; }
public string EntityID { get; set; }
public string ContactNum { get; set; }
}