title: Parsing json webservice Response with Gson (Expected BEGIN_OBJECT but was BEGIN_ARRAY)
body: <p>I'm trying to parse the spotify web-service response to get an artists' tracks which is like this: </p>
  
  <pre><code>{
  "info": {
      "num_results": 2974,
      "limit": 100,
      "offset": 0,
      "query": "foo",
      "type": "track",
      "page": 1
  },
  "tracks": [
      {
          "album": {
              "released": "2009",
              "href": "spotify:album:1zCNrbPpz5OLSr6mSpPdKm",
              "name": "Greatest Hits",
              "availability": {
                  "territories": "AD AR AT AU BE BG BO BR CA CH CL CO CR CY CZ DE DK DO EC EE ES FI FR GB GR GT HK HN HU IE IS IT LI LT LU LV MC MT MX MY NI NL NO NZ PA PE PH PL PT PY RO SE SG SI SK SV TR TW US UY"
              }
          },
          "name": "Everlong",
          "popularity": "0.79",
          "external-ids": [
              {
                  "type": "isrc",
                  "id": "USRW29600011"
              }
          ],
          "length": 249.986,
          "href": "spotify:track:07q6QTQXyPRCf7GbLakRPr",
          "artists": [
              {
                  "href": "spotify:artist:7jy3rLJdDQY21OgRLCZ9sD",
                  "name": "Foo Fighters"
              }
          ],
          "track-number": "3"
      }]
  }
  </code></pre>
  
  <p>I am using the Gson library to do this. So far I have tried this in my java code: </p>
  
  <pre><code>JsonParser parser = new JsonParser();
  JsonObject jObject = parser.parse(jsonString).getAsJsonObject();
  JsonArray jArray = jObject.get("tracks") .getAsJsonArray();
  
  
  Gson gson = new Gson();
  List&lt;Track&gt; trackArr = new ArrayList&lt;Track&gt;();
  
  Type collectiontype = new TypeToken&lt;Collection&lt;Track&gt;&gt;(){}.getType();
  Collection&lt;Track&gt; trackColl = gson.fromJson(jArray.toString(), collectiontype);
  </code></pre>
  
  <p>But I am getting the error : com.google.gson.JsonSyntaxException: java.lang.IllegalStateException: Expected BEGIN_OBJECT but was BEGIN_ARRAY</p>
  
  <p>I don't understand why is it expecting begin object if I am doing "getAsJsonArray()" when trying to get the "tracks" object whihc in the json string is an array [].</p>
  
  <p>The list of 'Track' was when I was doing this in a loop to get all the tracks into an array: </p>
  
  <pre><code>for (JsonElement jsonElement : jArray) {
    Type collectiontype = new TypeToken&lt;Collection&lt;Track&gt;&gt;(){}.getType();
    Collection&lt;Track&gt; trackCol = gson.fromJson(jsonElement, collectiontype);
    trackArr.add((Track) trackCol);
  
  }
  </code></pre>
  
  <p>What am I doind wrong here ? 
  I appreciate any guidance. </p>