我正在尝试从 httpResponse 中提取两组信息(以 JSON 的形式)-
1. 位置
2. 水果 = Apple 和 luckyNumber = 10 的城市。
{
"userInformation": {
"Name": "John",
"Location": "India"
},
"details": [
{
"fruit": "Apple",
"color": "Red",
"city": "New Delhi",
"luckyNumber": 10
},
{
"fruit": "Banana",
"color": "yellow",
"city": "Goa",
"luckyNumber": 12
}
]
}
为了提取位置,我尝试了以下代码:
def slurper = new JsonSlurper().parseText(httpResponse)
userLocation = slurper.userInformation.Location
这给了我一个错误-
javax.script.ScriptException: groovy.lang.MissingMethodException: No signature of method: groovy.json.JsonSlurper.parseText() is applicable for argument types: (java.util.LinkedHashMap) values: [[statusCode:200, reason:OK, headers:[Access-Control-Allow-Credential:true, ...], ...]] Possible solutions: parseText(java.lang.String), parse([B), parse([C), parse(java.io.File), parse(java.io.InputStream), parse(java.io.Reader)