将 JSON 文件与 JSON 响应进行比较时出现异常弹出窗口 window

Exception pop up window appears while comparing JSON file to JSON reponse

我正在比较 SOAPUI 中的 JSON 响应和 JSON 文件(ver - 4.6.4,免费软件) Groovy 脚本:

import groovy.json.JsonSlurper
import java.io.File

def ResponseMessage = testRunner.testCase.testSteps["Fi - Request 1"].testRequest.response.contentAsString

def jsonResp = new JsonSlurper().parseText(ResponseMessage)

def jsonFile = new File("C:/Users/new_2.json")
def InputJSON = new JsonSlurper().parseFile(jsonFile, 'UTF-8')

assert jsonResp.equals(InputJSON)

但是每次运行都会抛出异常弹出窗口:

groovy.lang.MissingMethodException: No signature of method: groovy.json.JsonSlurper.parseFile() is applicable for argument types: (java.io.File, java.lang.String) values: [C:\Users\new_2.json, UTF-8] Possible solutions: parseText(java.lang.String) error at line: 12

它对 parseText 也不起作用。 将其视为初学者脚本。

现在我面临全新的错误 -

groovy.json.JsonException: Lexing failed on line: 1, column: 1, while reading '', no possible valid JSON value or punctuation could be recognized.error at line: 9

JSON 文件内容的第 1 行: {

"Metadata": {
    "DocType": "Report",
    "SubType": "",
    "Content": {
        "Title": "Economic Comment",
        "Headline": "",
        "Summary": "",
        "Blurb": ""

    },
    "Priority": "1",
    "DocumentIDs": {
        "DocumentID": {
            "label": "",
            "type": "",
            "level": "",
            "value": ""
        }
    },

注意:此内容不完整。由于安全原因,我无法在此处粘贴完整 JSON

错误消息清楚地说明了备选方案。

更改以下声明:

def InputJSON = new JsonSlurper().parseFile(jsonFile, 'UTF-8')

收件人:

def InputJSON = new JsonSlurper().parse(jsonFile, 'UTF-8')

documentation

引用 JsonSlurper API