开发者

JSON + GPathResult

开发者 https://www.devze.com 2023-01-11 15:37 出处:网络
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

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
0

精彩评论

暂无评论...
验证码 换一张
取 消