我试图了解如何接收根元素" 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'来自回应。
谢谢,
答案 0 :(得分:4)
由于result
是Map
,您可以执行以下操作:
assert result.keySet() == [ 'person' ]