C# 在C语言中结合不同级别的词典#
我想用C#创建一个结构如下的字典:C# 在C语言中结合不同级别的词典#,c#,dictionary,C#,Dictionary,我想用C#创建一个结构如下的字典: { "PriceApproval": 0, "ListOffers": [ { "EAN": "7701410118349", "Stock": "3", "Price": "16000.00", "DiscountPrice": "20000.00", "AverageFreightCost": "25000.00", "PromiseDelivery": "1 a 10
{
"PriceApproval": 0,
"ListOffers": [
{
"EAN": "7701410118349",
"Stock": "3",
"Price": "16000.00",
"DiscountPrice": "20000.00",
"AverageFreightCost": "25000.00",
"PromiseDelivery": "1 a 10",
"Warranty": 50,
"IsFreeShipping": 0,
"IsEnviosExito": 0,
"IsFreightCalculator": 0,
"IsLogisticsExito": 0,
"IsUpdatedStock": 1,
"Currency": "COP",
"Periodicity": 1
}
]
}
我应该使用什么词典结构?
我想使用JSON将其作为httpRequestMessage
中的内容发送,如下所示:
{
"PriceApproval": 0,
"ListOffers": [
{
"EAN": "7701410118349",
"Stock": "3",
"Price": "16000.00",
"DiscountPrice": "20000.00",
"AverageFreightCost": "25000.00",
"PromiseDelivery": "1 a 10",
"Warranty": 50,
"IsFreeShipping": 0,
"IsEnviosExito": 0,
"IsFreightCalculator": 0,
"IsLogisticsExito": 0,
"IsUpdatedStock": 1,
"Currency": "COP",
"Periodicity": 1
}
]
}
Content=newstringcontent(JsonConvert.SerializeObject(info))
非常感谢。因为一个值是
int
(或者任何数字类型),另一个是另一个字典,其值是数字和字符串的混合体,所以您最好希望开箱即用的是字典。如果您想要更强类型的解决方案,可以定义类层次结构(当然,使用更有意义的名称):
你这样做的最终目标是什么?你打算用那本词典干什么?可能有更好的方法。我想将其作为内容添加到HttpRequestMessage中。您必须以何种格式发送它?理想情况下,将其作为JSON发送是最好的(这样您就不需要字典了)。但是你是说你必须将其作为表单数据发送吗?我实际上是使用代码StringContent(JsonConvert.SerializeObject(info))与JSON一起发送的,那么你为什么需要一个字典呢?类就是这样。