小编Mur*_*ham的帖子

使用带有正则表达式的 JSONAssert 进行 JSON 验证

我在一个使用 REST 接口的开源项目中工作。为了验证(将实际响应与预期匹配)我们在 JUnit 中的其余接口,我们想使用 JSONAssert。(https://github.com/skyscreamer/JSONassert)。但是我的用法有问题。请帮助解决它。

Expected JSON:
{
"objectId": "[^\\s]",
"protocol": "[^\\s]",
"hostName": "[^\\s]",
"port": "[^\\s]",
"commParams": "[^\\s]"
}
Run Code Online (Sandbox Code Playgroud)

备注:objectId/protocol/hostName/port/commParams 可以是任何值但不能为空

Actual JSON:
{
"objectId": "controller2",
"protocol": "ftp",
"hostName": "sdnorchestrator",
"port": "21",
"commParams": "username:tomcat, password:tomdog"
}
Run Code Online (Sandbox Code Playgroud)

问题1:JSON Assert的哪个接口,我需要使用哪个接口来解决上面的问题:下面一个?

JSONAssert.assertEquals("Expected JSON", "Actual JSON" new CustomComparator(
    JSONCompareMode.LENIENT_ORDER, new Customization(PREFIX, new        RegularExpressionValueMatcher<Object>())));
Run Code Online (Sandbox Code Playgroud)

问题 2:这里的 PREFIX 应该是什么?(我尝试使用“ ”、“.”、“ . ”但没有成功)

也欢迎针对上述问题提出任何其他建议(JSONAssert 除外)。

java json jsonassert

5
推荐指数
2
解决办法
3727
查看次数

标签 统计

java ×1

json ×1

jsonassert ×1