任何人都可以帮助为我的 JSON 格式编写 Newtonsoft JSON Deserializer。
我有以下 json 格式。
{
"success": true,
"message": "Missing ajax operation. Please contact administrator.",
"data": {
"mode": "new",
"data": {
"1": {
"CustomerCode": "CUST00001",
"Name": "Dell Asia Pacific Sdn. Bhd.",
"Add1": "Plot 76 Mukim 11, Bukit Tengah Industrial Park; Bukit Mertajam; Pulau Pinang; 14000",
"Add2": "",
"Add3": "",
"Daddr1": "Level 21, Suite 21.01, The Gardens South Tower, Mid Valley City, Lingkaran Syed Putra, ; Kuala Lumpur; Wilayah Persekutuan; 59200",
"Daddr2": "",
"Daddr3": "",
"Attn": "",
"Phone": "",
"PhoneA": "",
"Fax": "",
"Area": "",
"Agent": "",
"Email": "",
"CurrCode": "MYR",
"Business": "",
"Term": "30 Days"
},
"2": {
"CustomerCode": "CUST00002",
"Name": "Intel Technology Sdn Bhd",
"Add1": "Bayan Lepas Free Industrial Zone,Phase 3,Halaman Kampung Jawa; Bayan Lepas; Pulau Pinang; 11900",
"Add2": "",
"Add3": "",
"Daddr1": "1st Flr,Standard Chartered Bank Chambers,Lebuh Pantai;Penang; Kuala Lumpur; Wilayah Persekutuan; 10300",
"Daddr2": "",
"Daddr3": "",
"Attn": "",
"Phone": "",
"PhoneA": "",
"Fax": "",
"Area": "",
"Agent": "",
"Email": "",
"CurrCode": "MYR",
"Business": "",
"Term": "30 Days"
},
"3": {
"CustomerCode": "CUST00003",
"Name": "Petronas Carigali Sdn. Bhd.",
"Add1": "Tower 1, Petronas Twin Towers,Kuala Lumpur City Centre,; Kuala Lumpur; Wilayah Persekutuan; 50088",
"Add2": "",
"Add3": "",
"Daddr1": "Tower 1,Petronas Twin Towers,K.L.City Centre; Kuala Lumpur; Wilayah Persekutuan; 50088",
"Daddr2": "",
"Daddr3": "",
"Attn": "",
"Phone": "",
"PhoneA": "",
"Fax": "",
"Area": "",
"Agent": "",
"Email": "",
"CurrCode": "MYR",
"Business": "",
"Term": "30 Days"
}
}
}
}
我有以下类结构
public class CustomerInfo
{
public string CustomerCode { get; set; }
public string Name { get; set; }
public string Add1 { get; set; }
public string Add2 { get; set; }
public string Add3 { get; set; }
public string Daddr1 { get; set; }
public string Daddr2 { get; set; }
public string Daddr3 { get; set; }
public string Attn { get; set; }
public string Phone { get; set; }
public string PhoneA { get; set; }
public string Fax { get; set; }
public string Area { get; set; }
public string Agent { get; set; }
public string Email { get; set; }
public string CurrCode { get; set; }
public string Business { get; set; }
public string Term { get; set; }
}
public class CustomerData
{
public CustomerInfo customerInfo { get; set; }
}
public class Data
{
public string mode { get; set; }
public CustomerData custdata { get; set; }
}
public class CustomerRootObject
{
public bool success { get; set; }
public string message { get; set; }
public Data data { get; set; }
}
}
我很难解析我在下面编写的这种 json 格式,但它没有任何帮助,非常感谢。
List<CustomerRootObject> customerlist = JsonConvert.DeserializeObject<List<CustomerRootObject>> (json);
foreach (var info in customerlist) {Console.WriteLine(info.data.custdata.CustomerCode);}