JSON 응답에 어설 션을 실행하려면 SOAPUI에 다음과 같은 그루비 스크립트를 작성했습니다.Groovy에서 JsonSlurper를 사용하여 JSON 매개 변수를 추출하는 방법
Weather> main> Clouds 속성 및 JSON 응답 값에 대한 추출 및 어설 션을 위해 어설 션을 작성하는 데 어려움이 있습니다.
누군가 내 코드를 수정하여 원하는 값을 추출 할 수 있습니까?
감사합니다.
import groovy.json.JsonSlurper
def json = '''{
"coord": {
"lon": -0.13,
"lat": 51.51
},
"weather": [
{
"id": 801,
"main": "Clouds",
"description": "few clouds",
"icon": "02n"
}
],
"base": "stations",
"main": {
"temp": 281.644,
"pressure": 1027.43,
"humidity": 100,
"temp_min": 281.644,
"temp_max": 281.644,
"sea_level": 1035.14,
"grnd_level": 1027.43
},
"wind": {
"speed": 3.33,
"deg": 43.5005
},
"clouds": {
"all": 12
},
"dt": 1476231232,
"sys": {
"message": 0.0084,
"country": "GB",
"sunrise": 1476253200,
"sunset": 1476292372
},
"id": 2643743,
"name": "London",
"cod": 200
}'''
def result = new JsonSlurper().parseText(json)
log.info(result)
assert result.weather.main == "Clouds"