net.sf.json.groovy
public class JsonGroovyBuilder extends groovy.lang.GroovyObjectSupport
def books1 = builder.books { book = [title: "The Definitive Guide to Grails", author: "Graeme Rocher"] book = [title: "The Definitive Guide to Grails", author: "Graeme Rocher"] } def books2 = builder.books { book = new Book(title: "The Definitive Guide to Grails", author: "Graeme Rocher") book = new Book(title: "The Definitive Guide to Grails", author: "Graeme Rocher") } def books3 = builder.books { book = { title = "The Definitive Guide to Grails" author= "Graeme Rocher" } book = { title = "The Definitive Guide to Grails" author= "Graeme Rocher" } } def books4 = builder.books { book { title = "The Definitive Guide to Grails" author= "Graeme Rocher" } book { title = "The Definitive Guide to Grails" author= "Graeme Rocher" } } def books5 = builder.books { 2.times { book = { title = "The Definitive Guide to Grails" author= "Graeme Rocher" } } } def books6 = builder.books { 2.times { book { title = "The Definitive Guide to Grails" author= "Graeme Rocher" } } } all 6 books variables output the same JSON {"books": { "book": [{ "title": "The Definitive Guide to Grails", "author": "Graeme Rocher" },{ "title": "The Definitive Guide to Grails", "author": "Graeme Rocher" }] } }
Constructor and Description |
---|
JsonGroovyBuilder() |
Modifier and Type | Method and Description |
---|---|
java.lang.Object |
getProperty(java.lang.String name) |
java.lang.Object |
invokeMethod(java.lang.String name,
java.lang.Object arg) |
void |
setProperty(java.lang.String name,
java.lang.Object value) |
public java.lang.Object getProperty(java.lang.String name)
getProperty
in interface groovy.lang.GroovyObject
getProperty
in class groovy.lang.GroovyObjectSupport
public java.lang.Object invokeMethod(java.lang.String name, java.lang.Object arg)
invokeMethod
in interface groovy.lang.GroovyObject
invokeMethod
in class groovy.lang.GroovyObjectSupport
public void setProperty(java.lang.String name, java.lang.Object value)
setProperty
in interface groovy.lang.GroovyObject
setProperty
in class groovy.lang.GroovyObjectSupport
Copyright © 2006-2014 Json-lib. All Rights Reserved.