本文介绍了在C#中将复杂的json转换为数据表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



PFA低于json转换为c#中的数据表。



请帮我急。



{TotalPurchaseOrders:1,PurchaseOrders:[{RN:16872,OD:2017-12-25T13:41:51.637,RD: 2017-12-25T13:41:53.693,状态:更新,CD:null,VC:BIWL,VN:LLPL Bhiwandi Depot,CST#: , TIN#: , INVNUM: , 局部模板:[{ DD:空, DV:0.0 SAH:0.0, 其他:0.0, INVNUM :,注释:,项目:[{PC:TGFB100,HSN:3305.10.90,PN:TIGI SF SERIOUS COND 750ML,MRP :3000.0,RQO:0,CQO:1,UPO:1992.14,OTB:[{TC:SGST / UTGST 14%,TA:278.9000},{TC :CGST 14%,TA:278.9000}],OTN:SGST 28%,OT:557.8,RQD:0,CQD:1,UPD:1992.14, DTD:0,DVD:0.0,DT:557.8,DTB:[{TC:SGST / UTGST 14%,TA:278.9000},{TC:CGST 14 %,TA:278.9000}],DTN:SGST 28%,Notes:}}}]}],

错误:null}



我尝试过:



Hi,
PFA below json convert into datatable in c#.

Please help me urgent.

{"TotalPurchaseOrders":1,"PurchaseOrders":[{"RN":"16872","OD":"2017-12-25T13:41:51.637","RD":"2017-12-25T13:41:53.693","Status":"UPDATED","CD":null,"VC":"BIWL","VN":"LLPL Bhiwandi Depot","CST#":"","TIN#":"","InvNum":"","Partials":[{"DD":null,"DV":0.0,"SAH":0.0,"Other":0.0,"InvNum":"","Notes":"","Items":[{"PC":"TGFB100","HSN":"3305.10.90","PN":"TIGI SF SERIOUS COND 750ML","MRP":3000.0,"RQO":0,"CQO":1,"UPO":1992.14,"OTB":[{"TC":"SGST/UTGST 14%","TA":278.9000},{"TC":"CGST 14%","TA":278.9000}],"OTN":"SGST 28%","OT":557.8,"RQD":0,"CQD":1,"UPD":1992.14,"DTD":0,"DVD":0.0,"DT":557.8,"DTB":[{"TC":"SGST/UTGST 14%","TA":278.9000},{"TC":"CGST 14%","TA":278.9000}],"DTN":"SGST 28%","Notes":""}]}]}],
"Error":null}

What I have tried:

// To parse this JSON data, add NuGet 'Newtonsoft.Json' then do:
//
//    using QuickType;
//
//    var data = Welcome.FromJson(jsonString);

namespace QuickType
{
    using System;
    using System.Net;
    using System.Collections.Generic;

    using Newtonsoft.Json;

    public partial class Root
    {
        [JsonProperty("TotalPurchaseOrders")]
        public long TotalPurchaseOrders { get; set; }

        [JsonProperty("PurchaseOrders")]
        public PurchaseOrder[] PurchaseOrders { get; set; }

        [JsonProperty("Error")]
        public object Error { get; set; }
    }

    public partial class PurchaseOrder
    {
        [JsonProperty("RN")]
        public string Rn { get; set; }

        [JsonProperty("OD")]
        public System.DateTime Od { get; set; }

        [JsonProperty("RD")]
        public System.DateTime Rd { get; set; }

        [JsonProperty("Status")]
        public string Status { get; set; }

        [JsonProperty("CD")]
        public object Cd { get; set; }

        [JsonProperty("VC")]
        public string Vc { get; set; }

        [JsonProperty("VN")]
        public string Vn { get; set; }

        [JsonProperty("CST#")]
        public string Cst { get; set; }

        [JsonProperty("TIN#")]
        public string Tin { get; set; }

        [JsonProperty("InvNum")]
        public string InvNum { get; set; }

        [JsonProperty("Partials")]
        public Partial[] Partials { get; set; }
    }

    public partial class Partial
    {
        [JsonProperty("DD")]
        public object Dd { get; set; }

        [JsonProperty("DV")]
        public long Dv { get; set; }

        [JsonProperty("SAH")]
        public long Sah { get; set; }

        [JsonProperty("Other")]
        public long Other { get; set; }

        [JsonProperty("InvNum")]
        public string InvNum { get; set; }

        [JsonProperty("Notes")]
        public string Notes { get; set; }

        [JsonProperty("Items")]
        public Item[] Items { get; set; }
    }

    public partial class Item
    {
        [JsonProperty("PC")]
        public string Pc { get; set; }

        [JsonProperty("HSN")]
        public string Hsn { get; set; }

        [JsonProperty("PN")]
        public string Pn { get; set; }

        [JsonProperty("MRP")]
        public long Mrp { get; set; }

        [JsonProperty("RQO")]
        public long Rqo { get; set; }

        [JsonProperty("CQO")]
        public long Cqo { get; set; }

        [JsonProperty("UPO")]
        public double Upo { get; set; }

        [JsonProperty("OTB")]
        public Dtb[] Otb { get; set; }

        [JsonProperty("OTN")]
        public string Otn { get; set; }

        [JsonProperty("OT")]
        public double Ot { get; set; }

        [JsonProperty("RQD")]
        public long Rqd { get; set; }

        [JsonProperty("CQD")]
        public long Cqd { get; set; }

        [JsonProperty("UPD")]
        public double Upd { get; set; }

        [JsonProperty("DTD")]
        public long Dtd { get; set; }

        [JsonProperty("DVD")]
        public long Dvd { get; set; }

        [JsonProperty("DT")]
        public double Dt { get; set; }

        [JsonProperty("DTB")]
        public Dtb[] Dtb { get; set; }

        [JsonProperty("DTN")]
        public string Dtn { get; set; }

        [JsonProperty("Notes")]
        public string Notes { get; set; }
    }

    public partial class Dtb
    {
        [JsonProperty("TC")]
        public string Tc { get; set; }

        [JsonProperty("TA")]
        public double Ta { get; set; }
    }

    public partial class Root
    {
        public static Root FromJson(string json)
        {
            return JsonConvert.DeserializeObject<Root>(json);
        }
    }

    public static class Serialize
    {
        public static string ToJson(this Root self)
        {
            return JsonConvert.SerializeObject(self);
            //return JsonConvert.SerializeObject(self, Converter.Settings);
        }
    }

    //public class Converter
    //{
    //    public static readonly JsonSerializerSettings Settings = new JsonSerializerSettings
    //    {

    //        MetadataPropertyHandling = MetadataPropertyHandling.Ignore,
    //        DateParseHandling = DateParseHandling.None,
    //    };
    //}
}

推荐答案


这篇关于在C#中将复杂的json转换为数据表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-24 21:25