これが必要ですか? JsonBuilder
はすでにそれらをエスケープします:
def alicia = """
Moment of honesty
Someones gotta take the lead tonight
Who's it gonna be?
I'm gonna sit right here
And tell you all that comes to me
If "you" have something to say
"You" should say it right now
"""
def json = new groovy.json.JsonBuilder()
def songJson = json.songs {
song {
singer "Alicia"
lyrics alicia
}
}
assert json.toString() == '{"songs":{"song":{"singer":"Alicia","lyrics":"\n Moment of honesty\n Someones gotta take the lead tonight\n\n\n Who's it gonna be?\n I'm gonna sit right here\n And tell you all that comes to me\nIf \"you\" have something to say\n \"You\" should say it right now\n "}}}'
そうでない場合は、StringEscapeUtils
は興味があるかもしれません。
あなたは正しいです、それはそれらをエスケープします。とにかく、私はこれを見逃したか分からない。 – AbuMariam