因此,我试图从一次提取中解开我的回答:
fetch('restservices/users/', fetchOptions)
.then(function (response) {
if (response.ok) {
console.log('1');
console.log(response)
const responseSjon = response.json()
console.log('2');
console.log(responseSjon);
console.log('3');
// console.log(JSON.stringify(responseJson, null, 2));
console.log(JSON.stringify(responseJson));
console.log('4');
在Javascript中,我将响应解压缩为json with response.json.
[
{
"email":{
"chars":"CasaSuCasa",
"string":"CasaSuCasa",
"valueType":"STRING"
},
"naam":{
"chars":"Coyote",
"string":"Coyote",
"valueType":"STRING"
},
"hoeveelheid zoekopdrachten":{
"integral":true,
"valueType":"NUMBER"
}
},
{
"email":{
"chars":"syd@barrett.com",
"string":"syd@barrett.com",
"valueType":"STRING"
},
"naam":{
"chars":"CrazyDiamond",
"string":"CrazyDiamond",
"valueType":"STRING"
},
"hoeveelheid zoekopdrachten":{
"integral":true,
"valueType":"NUMBER"
}
}
]
我说它看起来是一个包含JsonArray对象的数组,包含json对象,对吗?
我的问题是如何在控制台中单独访问这些对象.日志(log)(xxx)?
编辑:
Map<String, User> commune = Community.getUserMap();
JsonArrayBuilder jab = Json.createArrayBuilder();
JsonObjectBuilder job = Json.createObjectBuilder();
commune.forEach((key, user) -> {
job.add("email", user.getEmail());
job.add("naam", user.getNaam());
job.add("role", user.getRole());
job.add("hoeveelheid zoekopdrachten", user.getAlleZoekertjes().size());
jab.add(job);
});
return ok(jab.build()).build();
}