How to parse JSON from a file with BaseX?

穿精又带淫゛_ 提交于 2021-01-29 09:43:26

问题


Writing a JSONObject to file file from Twitter4J seems to work, at least the file looks correct when opened manually:

public void writeJsonToFile(String fileName) throws FileNotFoundException, UnsupportedEncodingException, IOException {
    FileOutputStream fileOutputStream = null;
    OutputStreamWriter outputStreamWriter = null;
    BufferedWriter bufferedWriter = null;
    fileOutputStream = new FileOutputStream(fileName);
    outputStreamWriter = new OutputStreamWriter(fileOutputStream, "UTF-8");
    bufferedWriter = new BufferedWriter(outputStreamWriter);
    bufferedWriter.write(tweets.toString());
    bufferedWriter.close();
    outputStreamWriter.close();
    fileOutputStream.close();
}

but once the file is loaded into BaseX, or at least its JsonParser, how is the content actually parsed or processed? Must it not be converted to XML with the parser?

private void parseJsonFile(String fileName) throws IOException {
    JsonParser jsonParser = new JsonParser(new IOFile(fileName), new MainOptions());
}

full code on github.

来源:https://stackoverflow.com/questions/60016071/how-to-parse-json-from-a-file-with-basex

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!