解析存储在数据库中的json数组

时间:2017-10-04 09:29:48

标签: asp.net arrays json model-view-controller

    string json = db.PurchasedOrders.SingleOrDefault(x=>x.Id==2013).PurchasedItem;
var list = JsonConvert.DeserializeObject<List<purchasJsonObject>>(json);
            foreach (var item in list)
            {

                PurchasedOrderDetail details = new PurchasedOrderDetail()
                {


                    ItemId = item.Id,
                    Quantity = item.qty,
                    Rate = item.Price,
                    TotalAmount = (item.qty * item.Price),
                    Discount = Convert.ToDecimal(po.CashDiscount),
                    ExtraItem = 0,
                    SlNo = 0,
                    ReceiveQty = 0,

                };
                _db.PurchasedOrderDetails.Add(details);


            }
            _db.SaveChanges();


----------

尝试从数据库中检索json数据并解析它并添加另一个表“PurchasedOrderDetail”。但是当我执行代码时,PurchasedOrderDetail表仍然是空的...请你告诉我问题出在哪里?

0 个答案:

没有答案