有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

在JSONAssert java中使用正则表达式验证JSON字符串

我将预期的json字符串存储在参考资料下的json文件中,如下所示。json字符串由正则表达式组成。我使用JSONAssert库来比较两个json字符串

{
  "timestamp": "^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}.\\d{3}+\\d{4}$",
  "status": 415,
  "error": "Unsupported Media Type",
  "message": "Content type 'text/plain;charset=ISO-8859-1' not supported",
  "path": "/service/addUser"
}

我的实际响应由以下格式的时间戳组成2018-11-13T04:10:11.233+0000

    JSONAssert.assertEquals(getJsonBody(expected), response.asString(),false);

总是在正则表达式上给出以下错误

java.lang.AssertionError: timestamp
 Expected: ^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}.\d{3}+\d{4}$
      got: 2018-11-13T04:12:55.923+0000

对这个错误有什么建议吗


共 (0) 个答案