0

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

Community
  • 1
  • 1
user
  • 158
  • 6
  • 19

1 Answers1

0

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));

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.

user
  • 158
  • 6
  • 19
  • So if someone could point out how to deal with the multiple arrays I would be greatful – user Mar 17 '15 at 20:21
  • I find it very unlikely that MailChimp would return anything but syntactically correct JSON. I think you are deserializing the JSON incorrectly. – James Newman Mar 17 '15 at 23:45
  • Your right, I figured it out, I was just the way I handling the data. – user Mar 19 '15 at 14:51