2016-04-11 134 views
0

以下是GitHub從REST GET方法返回的內容。如何使用JSON解析它?如何解析從Groovy中的HttpBuilder返回的json響應?

response.success = { resp, reader -> 
      result = reader.text 
     } 

[{"login":"ghost","id":1,"avatar_url": ....},{"login":"github-enterprise","id":2,"avatar_url": ....}] 
+1

使用RestBuilder並將其解析爲您 –

回答

1

可以使用真棒工具,用於JSON的 - json slurper

def slurper = new JsonSlurper() 
    def result = slurper.parseText(result) 
    def firstLogin = result[0].login 
    def secondId = result[1].id