Created
June 16, 2018 08:21
-
-
Save pingkunga/9fb5ece90c8efa607708c76af1b3f3e6 to your computer and use it in GitHub Desktop.
GroovyParseJSON
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import groovy.json.JsonSlurper; | |
//ทำไว้ก่อนเดี๋ยวใน BPMN ใช้ Connector | |
apiString = "http://www.mocky.io/v2/5b24bac031000051006a7154"; | |
URL apiUrl = new URL(apiString); | |
def jsonslurper = new JsonSlurper(); | |
response = jsonslurper.parseText(apiUrl.text); | |
println("======================"); | |
println(response); | |
println("======================"); | |
//ดึงค่าจาก JSON แต่ละตัว่ | |
Map jsonResult = (Map) response; | |
println(jsonResult) | |
println("======================"); | |
println("projectid = " + jsonResult.get("projectId")); | |
println("requestId = " + jsonResult.get("requestId")); | |
println("requestby = " + jsonResult.get("requestby")); | |
println("requesttime = " + jsonResult.get("requesttime")); | |
//note | |
//http://groovy-lang.org/json.html | |
class requestitem | |
{ | |
String itemname | |
String itemtype | |
int itemqty | |
String itemamt | |
} | |
Map requestItem = (Map) jsonResult.get("requestitem") | |
println("======================"); | |
println(requestItem); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment