我创建了一个Json文件,我想写java对象作为Array元素.我用杰克逊.
try{
String json;
String phyPath = request.getSession().getServletContext().getRealPath("/");
String filepath = phyPath + "resources/" + "data.json";
File file = new File(filepath);
if (!file.exists()) {
System.out.println("pai nai");
file.createNewFile();
}
json = mapper.writerWithDefaultPrettyPrinter().writeValueAsString(story);
Files.write(new File(filepath).toPath(), Arrays.asList(json), StandardOpenOption.APPEND);
}
Run Code Online (Sandbox Code Playgroud)
这不是我想要的.它创建数据
{
"storyTitle" : "ttt",
"storyBody" : "tttt",
"storyAuthor" : "tttt"
}
{
"storyTitle" : "a",
"storyBody" : "a",
"storyAuthor" : "a"
}
Run Code Online (Sandbox Code Playgroud)
我只需要创建一个Json数组,我在其中添加java对象,数据应该是这样的
[{
"storyTitle" : "ttt",
"storyBody" : "tttt",
"storyAuthor" : "tttt"
}
,{
"storyTitle" : "a",
"storyBody" : "a",
"storyAuthor" : …
Run Code Online (Sandbox Code Playgroud) 我有一个字符串:String str = "[aa,bb,cc,dd]"
.我想将其转换为groovy中的列表[aa, bb, cc, dd]
.任何可用于此类型转换的groovy方法?
我在 grails 2.4.7 工作。最近我转移到 grails 3.Previously 我使用 grails 自定义标签进行 ajax 调用,如 remoteFunction、formRemote。这个标签不适用于最新版本。谁能告诉我使用 ajax 的最佳方法最新版本。