JSON + GPathResult
Could i parse JSON string as GPathResult ? Or something with similar interface... I just have some cod开发者_JAVA技巧e which doing some work with XML and i want to add JSON support. But GPathResult is very specific class and slightly differs form JSONObject or JSONArray.
You can use JSONSlurper from json-lib:
@Grapes([
@Grab(group='net.sf.json-lib', module='json-lib', version='2.3', classifier='jdk15')
])
import net.sf.json.groovy.*
def data = """{
"menu": {
"id": "file",
"value": "File",
"popup": {
"menuitem": [
{"value": "New", "onclick": "CreateNewDoc()"},
{"value": "Open", "onclick": "OpenDoc()"},
{"value": "Close", "onclick": "CloseDoc()"}
]
}
}
}"""
def json = new JsonSlurper().parseText( data )
println json.menu.popup.menuitem*.value
精彩评论