Groovy & JSON

Posted on by Kim

import groovy.json.JsonSlurper

class TestJson {

    static String json = "{shortText=1, errorContent=2, messageContent=3, errorCode=4}"
    static main(args) {
        def shortText = 1        def errorContent = 2        def messageContent = 3        def errorCode = 4        def jsonValue = "{" +
                "\"shortText\"     : ${shortText}," +
                "\"errorContent\"  : ${errorContent}," +
                "\"messageContent\": ${messageContent}," +
                "\"errorCode\"     : ${errorCode}" +
                "}"
        def result = new JsonSlurper().parseText jsonValue

        System.out.println "result.shortText..:${result.shortText}"        System.out.println "result.errorContent..:${result.errorContent}"        System.out.println "result.messageContent..:${result.messageContent}"        System.out.println "result.errorCode..:${result.errorCode}"
    }
}

0 Responses to "Groovy & JSON":