web services - Building complete JSON in grails -
my controller looks this:
def save() { js { def color = new color(params) color.save() def result if (!color.haserrors()) { result = [colorname: color.name, colorshde: color.shade] } else { result = "..." } render result json } } the json desire should this:
successful json
{ "meta": { "status": 200, "msg": "ok" }, "response": { "color": { "colorname": "red", "shade": "light } } } unsuccessful response:
{ "meta": { "status": 400, "msg": "something went worn" }, "response": { "color": { } } } question
how can modify controller action account both scenarios while returning json?
for successful response:
{ "meta": { "status": 200, "msg": "ok" }, "response": { "color": { "colorname": "red", "shade": "light } } } use:
result = [meta: [status: '200', msg: 'ok'], response:[color:[colorname: color.name, colorshde: color.shade] ] ] for unsuccessful response:
{ "meta": { "status": 400, "msg": "something went worn" }, "response": { "color": { } } } use
result = [meta: [status: '400', msg: 'wrong'], response:[color:[] ] ]
Comments
Post a Comment