【发布时间】:2017-05-09 11:02:21
【问题描述】:
我可以将以下 JSON 插入到 mongodb 中:
{
"Key1" : "Value1",
"Key2" : "Value2",
"Key3" : "Value3"
}
// C# (keys[] and values[] are already populated)
var document = new BsonDocument();
for(int i=0; i<keys.Length; i++)
{
document.Add(keys[i], values[i]);
}
我想插入一个嵌套的键/值对:
{
"Key1" : {
"subKey1" : "subValue1"
}
"Key2" : "Value2",
"Key3" : "Value3"
}
如有任何帮助,我们将不胜感激。
【问题讨论】:
-
“我想像这样插入一个嵌套的键/值对:”——根据在线测试人员的说法,这不是有效的 JSON。如果你提供了一个有效的 JSON 以及你想要的正确嵌套,那么我们可以弄清楚如何在 c# 中做同样的事情。有关 JSON 中嵌套对象和数组值的示例,请参阅 here。
-
我编辑了 JSON,使其现在有效。