title: get key names from JSON object using Gson
body: <p>I have a JSON object that I'd like to get the key names from and store them in an ArrayList.  I've used the following code</p>
  
  <pre><code>jsonData(String filename) {
      JsonParser parser = new JsonParser();
      JsonElement jsonElement = null;
  
      try {
          jsonElement = parser.parse(new FileReader(filename));
      } catch (JsonIOException | JsonSyntaxException | FileNotFoundException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
      }
  
      JsonObject jsonObject = jsonElement.getAsJsonObject();
  
      int i = 0;
      for (Entry&lt;String, JsonElement&gt; entry : jsonObject.entrySet()) {
          String key = entry.getKey();
          JsonElement value = entry.getValue();
  
          keys.add(key);
          i++;
      }
      nKeys = i;
  }
  </code></pre>
  
  <p>If I use this code with a simple JSON object </p>
  
  <pre><code>{
      "age":100,
      "name":"mkyong.com",
      "messages":["msg 1","msg 2","msg 3"]
  }
  </code></pre>
  
  <p>This works fine.  age, name, and messages (not the values) are added to my ArrayList.  Once I try and Use this same code with a more complex JSON like this</p>
  
  <pre><code>{"widget": {
      "debug": "on",
      "window": {
          "title": "Sample Konfabulator Widget",
          "name": "main_window",
          "width": 500,
          "height": 500
      },
      "image": { 
          "src": "Images/Sun.png",
          "name": "sun1",
          "hOffset": 250,
          "vOffset": 250,
          "alignment": "center"
      },
      "text": {
          "data": "Click Here",
          "size": 36,
          "style": "bold",
          "name": "text1",
          "hOffset": 250,
          "vOffset": 100,
          "alignment": "center",
          "onMouseUp": "sun1.opacity = (sun1.opacity / 100) * 90;"
      }
  }}
  </code></pre>
  
  <p>I only get the root key.  Can someone point me in the right direction with this?</p>
  
  <p>Thanks everyone!</p>