Created
September 14, 2011 12:26
-
-
Save kanemu/1216432 to your computer and use it in GitHub Desktop.
[groovy][jsonslurper]JsonSlurperで読み書きするとスラッシュがエスケープされる例。
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import groovy.json.* | |
import static groovy.json.JsonOutput.toJson | |
String sampleJson = '{"url":"http://www.yahoo.co.jp"}' | |
def jsonMap = new JsonSlurper().parseText(sampleJson) | |
String sampleJson2 = toJson(jsonMap) | |
assert sampleJson2 != sampleJson | |
assert sampleJson2 == '{"url":"http:\\/\\/www.yahoo.co.jp"}' | |
//JsonLexerを使うとエスケープが外せる。 | |
assert JsonLexer.unescape(sampleJson2) == sampleJson |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment