1

我遇到了错误排序 JSON 键的问题。我使用 mongo db,我需要发送一个创建用户表单命令。氛围-d JSON:

            Json a2 = Json([
                    "createUser": Json(req.form["user"]),
                    "pwd": Json(req.form["password"]),
                    "roles": Json([
                            Json([
                                "role": Json(req.form["access"]),
                                "db": Json("3dstore")
                            ])
                        ])
                    ]);
            logInfo(a2.toString());

输出:

[main(Wbp2) INF] {"roles":[{"role":"readWrite","db":"3dstore"}],"createUser":"111","pwd":"1"}

标准.json:

JSONValue a2 = JSONValue([
                    "createUser": JSONValue(req.form["user"]),
                    "pwd": JSONValue(req.form["password"]),
                    "roles": JSONValue([
                            JSONValue([
                                "role": JSONValue(req.form["access"]),
                                "db": JSONValue("3dstore")
                            ])
                        ])
                    ]);
            logInfo(a2.toString());

输出:

[main(vVOX) INF] {"createUser":"111","pwd":"1","roles":[{"db":"3dstore","role":"readWrite"}]}

因此我在 mongo 输出中得到一个错误:“errmsg”:“没有这样的命令:'roles'”

有任何想法吗?

4

0 回答 0