首页 > 解决方案 > 如何制作 JSON 记录

问题描述

我的任务是创建一个 JSON 记录,该记录将存储在 Elasticsearch 中,用于收集 UUID 编号。但我还必须记住,随着时间的推移,映射值的数量将会增加,所以我所做的必须能够适应以后的添加。

系统已经有一个算法可以解析和读取包含 UUID(以及 XML 文件中的其他数据)的 XML 文件,简而言之,他们希望我制作一个 JSON 记录来查看该数据和只需将 UUID 放在列表中即可。

这是我到目前为止为java编写的内容 -

public static List<Document> readPipelineFromFile(String configId) throws IOException, JSONException {
String data = readFromJar(recource: "configurations/" + configId + "/pipeline.json");

JSONArray jsonList = new JSONArray(data);
JSONObject extracted_message = new JSONObject(source: "(a:'foo', b:'bar')");
extracted_message.get("a");

ArrayList<Document> docList = new ArrayList<>();

for (int i = 0; i < jsonList.length(); i++) {
docList.add(Document.parse{jsonList.get(i).toString()));
}
return docList;
}

try {
JSONObject extracted_message = JSONObject.parse(message);
String tip_uuid = extracted_message.get("user_interface_fields").get("tip_identifier");
elastic.save(new ESObject (tip_uuid));
catch (NullPointerException ex) {
throw ParseException ("could not parse json!", ex);
} 

这就是我写的 JSON 记录

user_interface_fields: {
tip_identifier: {
uuid: value
} 
}

标签: javajsonxmlspringelasticsearch

解决方案


推荐阅读