如何在json结构中追加行?输入JSON由用户提供为html请求,每当我们需要添加日期或任何其他功能时新的JSON并返回为html响应。如何在请求消息中添加新行并作为回复发回
例如: 如果我的JSON文件是:{名称:ABC,年龄:12}然后我的新的输出JSON将{名称:ABC,年龄:12,日期:26/09/2017}
CODE:
InputStream inputStream = request.getInputStream();
String text = IOUtils.toString(inputStream, StandardCharsets.UTF_8.name());
JsonObject convertedObject = new Gson().fromJson(text, JsonObject.class);
convertedObject.addProperty("Date", "26/09/2017");
PrintWriter pw = response.getWriter();
pw.println(convertedObject.toString());
通过上面的代码等植物学JSON被删除只有日期显示:(
你可以尝试convertying JSON来图,来添加日期在该地图上,并转换回到json。看看这个https://stackoverflow.com/questions/443499/convert-json-to-map – mlecz