如何将文件解析为多行字符串?
我试图在jsonfile中转义双引号,所以我使用了多行字符串,但无法弄清楚如何将jsonfile作为多行字符串传递。
我有这样的代码:
import groovy.json.JsonSlurper
import groovy.json.JsonOutput
def script = new File('${jsonfile}')
if (!script || !script.exists()) {
println "Script file '${jsonfile}' doesn't exist"
System.exit(1)
}
File scriptContent = new File ("${script}")
def content = new JsonSlurper().parseText '''
scriptContent.text
'''
jsonfile:
{
"admin_id": "admin_user",
"admin_pwd": "admin_password",
"commands": [
"command one",
"command two",
"command \\\"three\\\" with double quotes",
"command four",
]
}