【发布时间】:2017-09-30 10:52:28
【问题描述】:
这可能不是最好的方法,但它是我知道如何用 c# 做的最好的方法。我正在尝试创建一个字典,然后稍后将其转换为 json。现在我只是想让字典匹配我以后想要的 json 格式。这是我到目前为止所拥有的:
`Dictionary<Dictionary<string, string>, Dictionary<string, List<List<Decimal>>>> testDict = new Dictionary<Dictionary<string, string>, Dictionary<string, List<List<Decimal>>>>() {
new Dictionary<string, string>() {
{ "test", "test" }
}
};`
这给了我以下错误:
没有与所需形参对应的参数
我不知道是什么原因造成的,任何帮助都会很棒,谢谢!
这是我要复制的 json 结构:
[
{
"target": "1",
"datapoints": [
[
67.0,
1491609600.0
]
]
},
{
"target": "2",
"datapoints": [
[
54.0,
1491091200.0
],
[
65.0,
1491177600.0
],
[
69.0,
1491609600.0
],
[
65.0,
1491696000.0
],
[
54.0,
1491868800.0
],
[
63.0,
1491955200.0
],
[
64.0,
1492214400.0
],
[
57.0,
1492732800.0
],
[
72.0,
1492819200.0
],
[
50.0,
1493337600.0
],
[
63.0,
1493424000.0
]
]
},
]
【问题讨论】:
-
看起来您缺少初始化程序中的值。您已经指定了一个键 (
new Dictionary<string, string>() { { "test", "test" }},但您缺少初始化程序的, value部分。要解决编译问题,请尝试以下操作:Dictionary<Dictionary<string, string>, Dictionary<string, List<List<Decimal>>>> testDict = new Dictionary<Dictionary<string, string>, Dictionary<string, List<List<Decimal>>>>() { { new Dictionary<string, string> { { "test", "test" } }, new Dictionary<string, List<List<decimal>>>() } }; -
100% 确定结构完全错误...如果您发布所需的 JSON 结构,也许有人可以发布您需要的真实类。
-
@Gusman 看看我更新的问题 :)
-
看起来应该是
List<SomeType>,其中SomeType是具有Target和DataPoints属性的自定义类......你真的不想要你的类型此刻宣布。 -
Dictionary<string, string>不能作为字典的键,因为它没有有意义的哈希码/等于...