Answer the question
In order to leave comments, you need to log in
How to add a save to a file?
Good afternoon. help me implement saving to a file what is output to the console with the line res.items.add .....
Here is part of my code
String ConvertToUniversalJson(String jsonVK) {
String json = "srwe";
ObjectMapper mapper = new ObjectMapper();//инициализация библиотеки Jackson
Example ex = null;
try {
ex = (Example) mapper.readValue(jsonVK, Example.class);
} catch (IOException e) {
e.printStackTrace();
}
JsonResult res = new JsonResult();
for (Item item : ex.getResponse().getItems()) {
res.items.add(new JsonResultItem(item.getId().toString(), item.getSizes().get(4).getUrl().toString()));
}
//System.out.println(item.getId().toString());
try {
json = mapper.writeValueAsString(res);
} catch (JsonGenerationException e) {
e.printStackTrace();
} catch (JsonMappingException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return json;
}
{"items":[{"id":"457239026","url":"https://sun9-69.userapi.com/c853428/v853428590/.....
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question