下面是我正在使用的代码
JSONObject requestParams = new JSONObject();
requestParams.put("something", "something value");
requestParams.put("another.child", "child value");
这就是 API 需要发布的方式
{
"something":"something value",
"another": {
"child": "child value"
}
}
我收到一条错误消息,指出“The another.child 字段是必需的。”
我如何通过restAssured 发布此内容?其他 API 不需要通过嵌套工作进行发布,因此我假设这就是它失败的原因。
最佳答案
您发布的内容是这样的,因为 JSONObject
没有点分隔键路径的概念。
{
"something":"something value",
"another.child": "child value"
}
您需要创建另一个JSONObject
JSONObject childJSON = new JSONObject():
childJSON.put("child", "child value");
requestParams.put("another", childJSON);
关于java - 构建嵌套的 JSONObject,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48950819/