C#构建JSON有效负载 - 列表中的列表

发布于 2025-02-10 23:57:28 字数 3460 浏览 3 评论 0原文

我在构建JSON付款方面遇到了巨大问题。 希望有人可以向我朝正确的方向推动。 有了Postman,很容易在这里挣扎,我在这里挣扎。

uomunitprices 让我头疼。

首先,我需要在

  • .net35
  • restsharp 105.2.3.0
  • newtonsoft.json 13.0.0.0

操作。

{
    "Id": "10006",
    "Barcodes": [
        {
            "Barcode": "1010006"
        }
    ],
    "UomUnitPrices": [
        {
            "Prices": [
                {
                    "PriceLevelId": "1",
                    "PriceValue": 5.000
                }
            ]
        }
    ]
}

中进行此

{
    "Id": "10006",
    "Barcodes": [
        {
            "Barcode": "1010006"
        }
    ],
    "UomUnitPrices": [
        {
            "Prices": [
                {
                    "PriceLevelId": "1",
                    "PriceValue": 5.000
                },
                {
                    "PriceLevelId": "100",
                    "PriceValue": 20.000
                },
                {
                    "PriceLevelId": "200",
                    "PriceValue": 10.000
                },
                {
                    "PriceLevelId": "300",
                    "PriceValue": 15.000
                },
                {
                    "PriceLevelId": "400",
                    "PriceValue": 17.500
                }
            ]
        }
    ],
    "Description": "Article Description",
    "GroupAId": "50",
    "VisibilityCriteriaId": "1",
    "IsValid": true,
    "MeasureUnitId": "pcs",
    "Vat1Id": "1",
    "Vat2Id": "2"
}

除了“价格”清单的“ uomunitprices”清单外,所有人都可以。

public partial class ArticlesDTO
{
    ...
    [JsonProperty("UomUnitPrices")]
    public List<UomUnitPrice> UomUnitPrices { get; set; }
    ...
}

public partial class UomUnitPrice
{
    [JsonProperty("Prices")]
    public IList<Price> Prices { get; set; }
}

public partial class Price
{
    [JsonProperty("PriceLevelId")]
    public string PriceLevelId { get; set; }

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

public partial class ArticlesDTO
{
     public ArticlesDTO CreateArticle(string id, string description, string groupAid, bool isValid, string measureUnitId, string vat1Id, string vat2Id)
    {
        Barcode barcode = new Barcode().CreateBarcode("String Barcode");
        UomUnitPrice uomUnitPrice = new UomUnitPrice().UomUnitPriceList(); //Here i need a solution

        ArticlesDTO article = new ArticlesDTO()
        {
            Id = id,
            Description = description,
            GroupAId = groupAid,
            VisibilityCriteriaId = 1,
            IsValid = true,
            MeasureUnitId = measureUnitId,
            Vat1Id = vat1Id,
            Vat2Id = vat2Id,
            Barcodes = new List<Barcode>() { barcode },
            UomUnitPrices = new List<UomUnitPrice>() { uomUnitPrice } // That can't be that hard...
        };
        return article;
    }
    public ArticlesDTO CreateArticle(DataRow dataRow)...
}

有人可以给我一个建议如何解决这个问题。

太谦卑了,我无法自己解决问题。 我看了几个youtube/udemy -videos,在stackoverflow上阅读很多(尤其是这个话题),但这无法解决我的问题。

最后,我将使用system.data.datarow创建“文章” -json-payload。 但是,只要我什至无法创建有效载荷,那将是一条到达那里的漫长道路。

感谢任何帮助/建议。

I have huge problems with building an JSON-payload.
Hopefully, someone can give me a push in the right direction.
With PostMan it's easy to CRUD-Articles, with C# i'm struggling here.

The UomUnitPrices makes me headache.

First of all, i need to do it in

  • .Net35
  • RestSharp 105.2.3.0
  • Newtonsoft.Json 13.0.0.0

I'm struggeling with List in List's

{
    "Id": "10006",
    "Barcodes": [
        {
            "Barcode": "1010006"
        }
    ],
    "UomUnitPrices": [
        {
            "Prices": [
                {
                    "PriceLevelId": "1",
                    "PriceValue": 5.000
                }
            ]
        }
    ]
}

The payload i should create, looks like this:

{
    "Id": "10006",
    "Barcodes": [
        {
            "Barcode": "1010006"
        }
    ],
    "UomUnitPrices": [
        {
            "Prices": [
                {
                    "PriceLevelId": "1",
                    "PriceValue": 5.000
                },
                {
                    "PriceLevelId": "100",
                    "PriceValue": 20.000
                },
                {
                    "PriceLevelId": "200",
                    "PriceValue": 10.000
                },
                {
                    "PriceLevelId": "300",
                    "PriceValue": 15.000
                },
                {
                    "PriceLevelId": "400",
                    "PriceValue": 17.500
                }
            ]
        }
    ],
    "Description": "Article Description",
    "GroupAId": "50",
    "VisibilityCriteriaId": "1",
    "IsValid": true,
    "MeasureUnitId": "pcs",
    "Vat1Id": "1",
    "Vat2Id": "2"
}

All works, except the "UomUnitPrices"-List with the "Prices"-List in it.

public partial class ArticlesDTO
{
    ...
    [JsonProperty("UomUnitPrices")]
    public List<UomUnitPrice> UomUnitPrices { get; set; }
    ...
}

public partial class UomUnitPrice
{
    [JsonProperty("Prices")]
    public IList<Price> Prices { get; set; }
}

public partial class Price
{
    [JsonProperty("PriceLevelId")]
    public string PriceLevelId { get; set; }

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

public partial class ArticlesDTO
{
     public ArticlesDTO CreateArticle(string id, string description, string groupAid, bool isValid, string measureUnitId, string vat1Id, string vat2Id)
    {
        Barcode barcode = new Barcode().CreateBarcode("String Barcode");
        UomUnitPrice uomUnitPrice = new UomUnitPrice().UomUnitPriceList(); //Here i need a solution

        ArticlesDTO article = new ArticlesDTO()
        {
            Id = id,
            Description = description,
            GroupAId = groupAid,
            VisibilityCriteriaId = 1,
            IsValid = true,
            MeasureUnitId = measureUnitId,
            Vat1Id = vat1Id,
            Vat2Id = vat2Id,
            Barcodes = new List<Barcode>() { barcode },
            UomUnitPrices = new List<UomUnitPrice>() { uomUnitPrice } // That can't be that hard...
        };
        return article;
    }
    public ArticlesDTO CreateArticle(DataRow dataRow)...
}

Can somebody give me an advice how to solve that problem.

It's so humbling that I can't solve the problem myself.
I watched several youtube/udemy -videos, read a lot on stackoverflow (especially this topic), but it wouldn't solve my problem.

Finally i would create the "Articles"-JSON-payload with a System.Data.DataRow.
But as long as I can't even create that payload, it's going to be a long road to get there.

Any help/advice is appreciated.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

囍孤女 2025-02-17 23:57:28

尝试将您的价格类型切换到仅列表而不是Ilist

Try to switch your Prices type to only List instead of IList

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文