如何在soapUI中格式化rest Json响应?

时间:2019-07-16 19:00:31

标签: groovy soapui

我正在从REST响应中获取JSON正文,其转义字符如下所示。如何使用Groovy脚本在soapUI中格式化JSON响应?

发件人:

{
  "employee": "{\"name\":\"John\", \"age\":30, \"city\":\"New York\"}"
}

收件人:

{   "employee": {
    "name": "John",
    "age": 30,
    "city": "New York"   } }

1 个答案:

答案 0 :(得分:0)

简单的字符串替换即可完成工作:

def escapedString = '''{"employee":"{\"name\":\"John\", \"age\":30, \"city\":\"New York\"}"}'''
def unescapedString = escapedString.replaceAll("\\\\", "")

System.out.println unescapedString

这将产生:

{"employee":"{"name":"John", "age":30, "city":"New York"}"}