Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot resolve method spliterator JSONArray java8 streams

I am trying to use streams on a JSONArray (imported from org.json.JSONArray) (following another stackoverflow thread here: How to iterate over a jsonarray in java8. However, my IDE (intellij) complains that it cannot resolve the method spliterator. What am I missing? I can't find any solution online. Below is the code:

private static Stream<Object> arrayToStream(JSONArray array) {
    return StreamSupport.stream(array.spliterator(), false);
}

Below in the screenshot, you can see the error the IDE is showing me: enter image description here

like image 835
coffeeak Avatar asked Dec 05 '25 19:12

coffeeak


1 Answers

Have you imported the correct dependencies?

Here you are the dependency from Maven repository which work fine!

 <!-- https://mvnrepository.com/artifact/org.json/json -->
       <dependency>
           <groupId>org.json</groupId>
           <artifactId>json</artifactId>
           <version>20190722</version>
       </dependency>

With gradle:

compile group: 'org.json', name: 'json', version: '20190722'

Or you can download it from here:
https://repo1.maven.org/maven2/org/json/json/20190722/json-20190722.jar

like image 199
jordi Avatar answered Dec 08 '25 07:12

jordi



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!