fork(7) download
  1. def jsonString = """{
  2. "menu": {
  3. "id": "file",
  4. "value": "File",
  5. "popup": {
  6. "menuitem": [
  7. {
  8. "value": "New",
  9. "onclick": ["CreateNewDoc()","hai"],
  10. "newnode":"added"
  11. }
  12. ]
  13. }
  14. }
  15. }"""
  16.  
  17. def printDetails = { key, value -> println "Key - $key, its value is \"${value}\" and is of typpe ${value.class}" }
  18.  
  19. def showMap = { map -> map.collect { k, v -> printDetails (k,v) } }
  20.  
  21. def json = new groovy.json.JsonSlurper().parseText(jsonString)
  22. def mItem = json.menu.popup.menuitem
  23. if (mItem instanceof List) {
  24. mItem.collect { showMap it }
  25. }
  26. println 'done'
Success #stdin #stdout 1.02s 86184KB
stdin
Standard input is empty
stdout
Key - newnode, its value is "added" and is of typpe class java.lang.String
Key - onclick, its value is "[CreateNewDoc(), hai]" and is of typpe class java.util.ArrayList
Key - value, its value is "New" and is of typpe class java.lang.String
done