我需要根据要发送给我的webService的对象列表创建JSONARRAY,然后使用javaScript获取此JSONArray并再次创建对象。
观察:这些对象在JSON文件中。
public static List<Funcionario> pegaFuncionario() throws JsonParseException, JsonMappingException, IOException {
list = new ArrayList<>();
mapper = new ObjectMapper();
reader = new BufferedReader(new FileReader("arquivos/usuarios"));
while ((line = reader.readLine()) != null) {
list.add(mapper.readValue(line, Funcionario.class));
}
if (reader != null) {
try {
reader.close();
} catch (IOException e) {
e.printStackTrace();
}
}
return list;
}
答案 0 :(得分:0)
我认为是因为您需要通过HTTP将其发送到Web服务,因此需要JSON数组字符串。 Jackson可以将对象写入JSON字符串,并将List
视为JSONArray
:
ObjectMapper mapper = new ObjectMapper();
List<Funcionario> list = pegaFuncionario();
String jsonArray = mapper.writeValueAsString(list);