What's wrong with the JSONObject?

Hi... I am trying to read my JSON database, but I get this error: "A JSONObject text must begin with '{'

Apparently, I understand that my database starts with a '[' and I have tried to remove it concerning the dB into a text object, but then I can have the JSON structure...

Also, I can't edit my database, so I have to do it in Processing... Does anyone know how this can be fixed?

I checked some JAVA solutions in stackoverflow but there were not helpful.

I've started praying..... let's see...!

Answers

  • can you post the first 7 lines of the file?

    maybe you have to add { } ...

  • This is the structure of my JSON:

    [{"_id":"0", "message":"Blah", "score":1, "year":2016, "month":2, "day":24, "hour":12, "minute":30, "second":56}]

    As I understand, I have to remove the square brackets for the JSONObject to read it properly. The question is how...?

  • Answer ✓

    Have you tried JSONArray instead? L-)
    https://Processing.org/reference/JSONArray.html

  • edited February 2016

    Great, it helped, this is what I did:

    JSONArray json;
    
    void setup() {
      json = loadJSONArray("http:" + "//json.net/getdata");
    
      for (int i = 0; i < json.size (); i++) {
        JSONObject values = json.getJSONObject(i); 
        int score = values.getInt("score");
        println(score);
      }
    }
    
Sign In or Register to comment.