将JSON数组传递给基于Neo4j服务器的java类的正确方法是什么?
我在尝试将加载到JSON数组中的数据成功地传递给运行在Neo4j服务器上的java类时遇到了麻烦。我的目的是将一个条目列表从客户端传递到服务器-这里没有什么特别的。我正在做的是读取客户端的条目,将这些条目加载到JSON对象中,然后将每个JSON对象放入一个JSON数组,然后将该数组传递给服务器进行进一步处理 下面是加载json对象和数组的客户端代码的一部分。注:下表为 只有与json相关的代码,没有try/catch和代码中的其他项将JSON数组传递给基于Neo4j服务器的java类的正确方法是什么?,java,json,neo4j,Java,Json,Neo4j,我在尝试将加载到JSON数组中的数据成功地传递给运行在Neo4j服务器上的java类时遇到了麻烦。我的目的是将一个条目列表从客户端传递到服务器-这里没有什么特别的。我正在做的是读取客户端的条目,将这些条目加载到JSON对象中,然后将每个JSON对象放入一个JSON数组,然后将该数组传递给服务器进行进一步处理 下面是加载json对象和数组的客户端代码的一部分。注:下表为 只有与json相关的代码,没有try/catch和代码中的其他项 JSONArray jsonArray = new J
JSONArray jsonArray = new JSONArray();
JSONObject jsonObject = new JSONObject();
jsonObject.put("field1", field1Value1);
jsonObject.put("field2", field2Value1);
jsonObject.put("field3", field3Value1);
jsonArray.put(jsonObject);
JSONObject jsonObject = new JSONObject();
jsonObject.put("field1", field1Value2);
jsonObject.put("field2", field2Value2);
jsonObject.put("field3", field3Value2);
jsonArray.put(jsonObject);
下面是处理等式中http post部分的客户端代码——我相信这是可以的
StringEntity stringEntity = new StringEntity(jsonArray.toString());
stringEntity.setContentType("application/json");
HttpPost post = new HttpPost(
"http://"server":7474/db/data/ext/serverSideClass/graphdb/processJSONData");
post.setEntity(stringEntity);
HTTPPostResponseResults httpResponse = new HTTPPostResponseResults();
httpResponse.checkResponse(post);
这是服务器端代码的方法接口,我相信这就是我的问题所在。我认为参数类型需要与JSONArray不同,但不确定是什么
@Name("processJSONData")
@Description("process the data passed in.")
@PluginTarget(GraphDatabaseService.class)
public String processJSONData(@Source GraphDatabaseService graphDb,
@Parameter(name = "jsonArray") JSONArray jsonArray) {
而且。。。下面是抛出的错误
"message" : "java.util.ArrayList cannot be cast to java.util.Map",
"exception" : "BadInputException",
"fullname" : "org.neo4j.server.rest.repr.BadInputException",
"stacktrace" : [ "org.neo4j.server.rest.repr.formats.JsonFormat.readMap(JsonFormat.java:92)",
"org.neo4j.server.rest.repr.RepresentationFormat.readParameterList(RepresentationFormat.java:97)",
"org.neo4j.server.rest.web.ExtensionService.invokeGraphDatabaseExtension
以上内容应涵盖与此张贴相关的项目。如果有什么需要澄清的,请让我知道,我会提供它。先谢谢你