title: Expected BEGIN_ARRAY but was BEGIN_OBJECT when using GSON
body: <p>Ok, I know that many of questions like that have been asked, but I have a specific question, which none of the others has. I want to know how I'd go on to parse following JSON file with GSON.</p>
  
  <pre><code>{
          "BUYER": {
                  "IGN": "MGlolenstine",
                  "ProductID": "51"
          },
          "BUYER": {
                  "IGN": "MGlolenstine",
                  "ProductID": "55"
          },
          "BUYER": {
                  "IGN": "MGlolenstine",
                  "ProductID": "0"
          },
          "BUYER": {
                  "IGN": "MGlolenstine",
                  "ProductID": "51"
          },
          "BUYER": {
                  "IGN": "MGlolenstine",
                  "ProductID": "56"
          }
  }
  </code></pre>
  
  <p>because when I use this code</p>
  
  <pre><code>Scanner scanner = new Scanner( new File(path) );
  String text = scanner.useDelimiter("\\A").next();
  Gson gson = new GsonBuilder().create();
  ArrayList&lt;Purchases&gt; p = gson.fromJson(new FileReader(path), Purchases.class);
  for(int i = 0; i &lt; p.size(); i++){
      arg0.sendMessage(ChatColor.GOLD+"Player: "+p.get(i).BUYER.IGN);
      arg0.sendMessage(ChatColor.GOLD+"ProductID: "+String.valueOf(p.get(i).BUYER.ProductID));
  }
  scanner.close();
  </code></pre>
  
  <p>I get the error</p>
  
  <pre><code>Caused by: com.google.gson.JsonSyntaxException: java.lang.IllegalStateException: Expected BEGIN_ARRAY but was BEGIN_OBJECT at line 2 column 12
  </code></pre>
  
  <p>Here just posting the classes I have for the JSON code</p>
  
  <pre><code>public class Purchases{
      PlayerRank BUYER;
  }
  
  public class PlayerRank{
      String IGN;
      int ProductID;
  }
  </code></pre>
  
  <p>The problem is probably me not knowing how the JSON arrays and objects look like.
  Could someone please explain the difference between JSONArray and JSONObject in my JSON code?</p>
  
  <p>Thank you in advance.</p>
  
  <p>EDIT: So this is the fixed JSON</p>
  
  <pre><code>{
  "buyers" : [
      { "IGN" : "MGlolenstine", "ProductID" : "51" },
      { "IGN" : "MGlolenstine", "ProductID" : "55" },
      { "IGN" : "MGlolenstine", "ProductID" : "0" },
      { "IGN" : "MGlolenstine", "ProductID" : "51" },
      { "IGN" : "MGlolenstine", "ProductID" : "56" }
  ]
  </code></pre>
  
  <p>}</p>
  
  <p>Fixed Java code:</p>
  
  <pre><code>Scanner scanner = new Scanner( new File(path) );
  String text = scanner.useDelimiter("\\A").next();
  Gson gson = new GsonBuilder().create();
  Purchases p = gson.fromJson(new FileReader(path), Purchases.class);
  for(int i = 0; i &lt; p.buyers.length; i++){
      arg0.sendMessage(ChatColor.GOLD+"Player: "+p.buyers[i].IGN);
      arg0.sendMessage(ChatColor.GOLD+"ProductID: "+String.valueOf(p.buyers[i].ProductID));
  }
  </code></pre>
  
  <p>And lastly the classes:</p>
  
  <pre><code>public class Purchases{
      PlayerRank buyers[];
  }
  
  public class PlayerRank{
      String IGN;
      int ProductID;
  }
  </code></pre>
  
  <p>Thanks to everyone for the help!</p>