import com.avoka.component.http.GetRequest
import groovy.json.JsonOutput
import groovy.json.JsonSlurper
import org.apache.http.client.methods.CloseableHttpResponse
import org.apache.http.client.methods.HttpGet
import org.apache.http.client.utils.URIBuilder
import org.apache.http.impl.client.CloseableHttpClient
import org.apache.http.impl.client.HttpClients
import org.apache.http.util.EntityUtils
CloseableHttpClient client = HttpClients.createDefault();
def uri = new URIBuilder("https://randomuser.me/api/?results=30&nat=US")
HttpGet request = new HttpGet(uri.build())
request.setHeader("content-type", "application/json")
CloseableHttpResponse response = client.execute(request);
String json = EntityUtils.toString(response.getEntity());
def jsonSlurper = new JsonSlurper()
def object = jsonSlurper.parseText(json)
def users =[:]
for (int i =0 ; i< object.results.size() ; i++){
def contactJson = object.results[i]
users.gender = contactJson.gender
users.firstname =contactJson.name.first
users.lastname =contactJson.name.last
users.location = contactJson.location.collect { it ->
[Street : it.street,
city : it.city,
state : it.state,
postcode : it.postcode]
}
users.phone =contactJson.phone
users.dateofbirth = contactJson.dob.age
users.nationality =contactJson.nat
}
print users
I am looping the json object and trying to populate the response using maps.
Caught: groovy.lang.MissingPropertyException: No such property: street for class: java.util.LinkedHashMap$Entry
groovy.lang.MissingPropertyException: Нет такого свойства: улица для класса: java.util.LinkedHashMap $ Запись на post $ _run_closure1.doCall (post.groovy: 33) на post.run (post.groovy: 31)
Получение этой ошибки, а также получение одного пользователя для пользователя печати, но размер списка составляет 30.