简体   繁体   中英

Parsing Multiple (Thousands) of JSON objects from a url in Java

I have to deal with multiple thousands of JSON objects that I am getting from a url in Java. I tried using the usual JSON code I have but I get the error Exception in thread "main" org.json.JSONException: A JSONObject text must begin with '{' at 2 [character 3 line 1]

Because there are no curly braces present in the JSON data only square brackets around each JSON object.

I would appreciate any help I can get with this.

BTW the code I was trying to use was the code posted in the highest answer here: simplest way to read json from a URL in java

Thanks

I have found out the correct method for handling this.

Once I treat the data as JSON Arrays it works fine. I then specify the field I want by number reference rather that name. For example: System.out.println(json.toString()); System.out.println(json.get(2)); System.out.println(json.toString()); System.out.println(json.get(2));

will print the header row then print the second field of the header row.

To process the next object, I presume a loop advancing the line number on each recursion would work fine.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM