Skip to content

Instantly share code, notes, and snippets.

@toby55kij
Created November 5, 2011 08:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save toby55kij/1341278 to your computer and use it in GitHub Desktop.
Save toby55kij/1341278 to your computer and use it in GitHub Desktop.
groovy.json.StreamingJsonBuilderのサンプル
//StreamingJsonBuilderのサンプル
import groovy.json.JsonOutput
import groovy.json.StreamingJsonBuilder
def data = {
people {
person {
firstName 'Yasuharu'
lastName 'Hayami'
// Named arguments are valid values for objects too
address(
city: 'Niigata',
country: 'Japan',
zip: 9501115
)
married false
// a list of values
conferences 'JGGUG', 'JJUG'
}
}
}
//StringWriterを使う
def writer = new StringWriter()
//StreamingJsonBuilderを使う
def builder = new StreamingJsonBuilder(writer)
builder data
println writer.toString()
//結果が等しいことを確認
assert writer.toString() == JsonOutput.toJson(data)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment