BaseXException: ресурс не найден. при добавлении JSONObject - PullRequest
0 голосов
/ 16 февраля 2020

Как мне сохранить JSONObject до BaseX?

JSONObject построен как {"0":"","1":"z10","2":"y9","3":"x7","4":"atrib6","name":"alice"}, что выглядит как минимум допустимым JSON.

:

thufir@dur:~/NetBeansProjects/groupBaseX$ 
thufir@dur:~/NetBeansProjects/groupBaseX$ gradle run

> Task :run FAILED                                                                              
Feb. 16, 2020 8:32:51 A.M. basex.DatabaseHelper persist
INFO: {"0":"","1":"z10","2":"y9","3":"x7","4":"atrib6","name":"alice"}
Exception in thread "main" org.basex.core.BaseXException: Resource not found.
        at org.basex.core.Command.execute(Command.java:94)
        at org.basex.core.Command.execute(Command.java:116)
        at basex.DatabaseHelper.persist(DatabaseHelper.java:79)
        at groupBaseX.App.run(App.java:26)
        at groupBaseX.App.main(App.java:30)

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':run'.
> Process 'command '/home/thufir/.sdkman/candidates/java/12.0.1-zulu/bin/java'' finished with non-zero exit value 1

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 1s
3 actionable tasks: 2 executed, 1 up-to-date
thufir@dur:~/NetBeansProjects/groupBaseX$                   

код:

    public void persist(JSONArray jsonPeople) throws MalformedURLException, BaseXException {
        new Set("parser", "json").execute(context);
        new Open(databaseName).execute(context);

        JSONObject jsonPerson = null;
        for (int i = 0; i < jsonPeople.length(); i++) {
            jsonPerson = new JSONObject(jsonPeople.getJSONObject(i).toString());
            log.info(jsonPerson.toString());
            new Add(jsonPerson.toString()).execute(context);
        }
    }

Обратите внимание, что JSON фактически добавляется как String; полный исходный код здесь .

...