如何使用JsonSlurper获取根元素?

时间:2014-03-19 09:08:56

标签: json groovy soapui

我试图了解如何接收根元素" person"来自流动的json代码:

def slurper = new JsonSlurper()
def result = slurper.parseText('{"person":{"name":"Guillaume","age":33,"pets":["dog","cat"]}}')

 assert result.person.name == "Guillaume"
 assert result.person.age == 33
 assert result.person.pets.size() == 2
 assert result.person.pets[0] == "dog"
 assert result.person.pets[1] == "cat"

我需要实际的名字' person'来自回应。

谢谢,

1 个答案:

答案 0 :(得分:4)

由于resultMap,您可以执行以下操作:

assert result.keySet() == [ 'person' ]