我有一个json结果列表,我想将此项目值保存到我的MSSql Db。 我尝试每个循环对象并获取值但子项值不来。有人帮帮我吗?
Hier是我的json结果和代码的类。
Json的对象类
public class Price
{
[JsonProperty("currency")]
public string currency { get; set; }
[JsonProperty("amount")]
public float amount { get; set; }
}
public class TotalPrice
{
[JsonProperty("currency")]
public string currency { get; set; }
[JsonProperty("amount")]
public float amount { get; set; }
}
public class items
{
[JsonProperty("lineItemId")]
public string lineItemId { get; set; }
[JsonProperty("listingId")]
public string listingId { get; set; }
[JsonProperty("merchantId")]
public string merchantId { get; set; }
[JsonProperty("hbSku")]
public string hbSku { get; set; }
[JsonProperty("merchantSku")]
public string merchantSku { get; set; }
[JsonProperty("quantity")]
public int quantity { get; set; }
[JsonProperty("price")]
public Price price { get; set; }
[JsonProperty("vat")]
public double vat { get; set; }
[JsonProperty("totalPrice")]
public TotalPrice totalPrice { get; set; }
[JsonProperty("cargoPaymentInfo")]
public string cargoPaymentInfo { get; set; }
[JsonProperty("properties")]
public IList<object> properties { get; set; }
[JsonProperty("productName")]
public string productName { get; set; }
[JsonProperty("orderNumber")]
public string orderNumber { get; set; }
[JsonProperty("orderDate")]
public DateTime orderDate { get; set; }
public IList<items> item { get; set; }
}
public class Orders
{
[JsonProperty("id")]
public string id { get; set; }
[JsonProperty("status")]
public string status { get; set; }
[JsonProperty("customerId")]
public string customerId { get; set; }
[JsonProperty("orderDate")]
public DateTime orderDate { get; set; }
[JsonProperty("unpackedDate")]
public object unpackedDate { get; set; }
[JsonProperty("barcode")]
public string barcode { get; set; }
[JsonProperty("packageNumber")]
public string packageNumber { get; set; }
[JsonProperty("shippingAddressDetail")]
public string shippingAddressDetail { get; set; }
[JsonProperty("recipientName")]
public string recipientName { get; set; }
[JsonProperty("shippingCountryCode")]
public string shippingCountryCode { get; set; }
[JsonProperty("shippingDistrict")]
public string shippingDistrict { get; set; }
[JsonProperty("shippingCity")]
public string shippingCity { get; set; }
[JsonProperty("email")]
public string email { get; set; }
[JsonProperty("phoneNumber")]
public string phoneNumber { get; set; }
[JsonProperty("companyName")]
public string companyName { get; set; }
[JsonProperty("billingAddress")]
public string billingAddress { get; set; }
[JsonProperty("billingCity")]
public string billingCity { get; set; }
[JsonProperty("billingDistrict")]
public string billingDistrict { get; set; }
[JsonProperty("taxOffice")]
public string taxOffice { get; set; }
[JsonProperty("taxNumber")]
public string taxNumber { get; set; }
[JsonProperty("identityNo")]
public string identityNo { get; set; }
[JsonProperty("items")]
public IList<items> items { get; set; }
}
和CodeBehind
WebRequest req = WebRequest.Create(link);
req.Method = method;
req.Headers["Authorization"] = "Basic " + Convert.ToBase64String(Encoding.Default.GetBytes(yetki));
req.ContentType = "application/json";
HttpWebResponse resp = req.GetResponse() as HttpWebResponse;
string result = "";
using (StreamReader reader = new StreamReader(resp.GetResponseStream()))
{
result = reader.ReadToEnd(); // do something fun...
List<Orders> sip = JsonConvert.DeserializeObject<List<Orders>>(result);
foreach(var item in sip)
{
string id = item.id;
string status = item.status;
string barc = item.barcode;
}
List<items> items = JsonConvert.DeserializeObject<List<items>>(result);
foreach(var item in items)
{
bar = item.merchantSku;
string on = item.orderNumber;
}
float fyt = 0;
List<Price> prc = JsonConvert.DeserializeObject <List<Price >>(result);
foreach(var f in prc)
{
fyt = f.amount;
}
}
}
那么,如何将此结果保存到DB:/ 我做了3-4天的搜索,我的思绪停止了
ps:第一个列表运行但第二个列表&lt;&gt;数组返回空值juste datetime实现vat和qnty返回0