我有以下 json 回應。如何從 json 回應中讀取 CustomerList 資料。我會將這些資料系結到gridview。使用 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"
}
]
}
}
uj5u.com熱心網友回復:
我不知道您使用的是哪種網格視圖,但您可以通過 2 種方式從 json 獲取資料
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>>();
現在您可以使用 dataTable 或客戶串列作為 gridview 的來源
如果您決定使用串列,則需要創建此類
public class Customer
{
public string EntityName { get; set; }
public string EntityID { get; set; }
public string ContactNum { get; set; }
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/494033.html
下一篇:在d3.js問題中決議時間戳
