jenkins错误:hudson.remoting.ProxyException:net.sf.json.JSONException:无效的JSON字符串

x7rlezfr  于 2023-08-03  发布在  Jenkins
关注(0)|答案(1)|浏览(140)

我在尝试解析Jenkins多分支管道中的json文件时遇到以下错误:

def payload = writeJSON(file: "hostname.json", json: env.config)
json = readJSON file: 'hostname.json'
data = new JsonSlurperClassic().parseText(json)
echo "Original Payload: ${data.software_maintainance_package_destination}"

字符串
json文件

{
  "software_maintainance_package_name": [
    {"AgentName":"TrendMicro", "process":"Install", "OS":"linux"}],
  "software_maintainance_package_destination": [
    {"name":"InstanceIds", "detail":"186.12.45.23"}],
  "siteName": "us-east-1",  
  "siteEnvironment": "OnPrem",
  "ReferenceTicket": "RITM0923008",
}


错误代码:

hudson.remoting.ProxyException: net.sf.json.JSONException: Expected a ',' or ']' at character 36 of [software_maintainance_package_name:[[AgentName:TrendMicro, process:Install, OS:linux]], software_maintainance_package_destination:[[name:InstanceIds, detail:186.12.45.23]], siteName:us-east-1, siteEnvironment:OnPrem, ReferenceTicket:RITM0923008]
    at net.sf.json.util.JSONTokener.syntaxError(JSONTokener.java:499)
    at net.sf.json.JSONArray._fromJSONTokener(JSONArray.java:1182)
    at net.sf.json.JSONArray._fromString(JSONArray.java:1192)
    at net.sf.json.JSONArray.fromObject(JSONArray.java:127)
    at net.sf.json.JSONSerializer.toJSON(JSONSerializer.java:137)
    at net.sf.json.JSONSerializer.toJSON(JSONSerializer.java:103)
    at net.sf.json.JSONSerializer.toJSON(JSONSerializer.java:84)
[Bitbucket] Notifying commit build result
[Bitbucket] Build result notified
Finished: FAILURE

kyks70gy

kyks70gy1#

你的JSON似乎是无效的。以下是正确的JSON。

{
    "software_maintainance_package_name": [{
        "AgentName": "TrendMicro",
        "process": "Install",
        "OS": "linux"
    }],
    "software_maintainance_package_destination": [{
        "name": "InstanceIds",
        "detail": "186.12.45.23"
    }],
    "siteName": "us-east-1",
    "siteEnvironment": "OnPrem",
    "ReferenceTicket": "RITM0923008"
}

字符串

相关问题