โพสต์ของฉันอาจเป็นประโยชน์สำหรับผู้อื่นดังนั้นโปรดจินตนาการว่าคุณมีแผนที่ที่มีวัตถุเฉพาะเป็นค่าเช่นนี้:
{  
   "shopping_list":{  
      "996386":{  
         "id":996386,
         "label":"My 1st shopping list",
         "current":true,
         "nb_reference":6
      },
      "888540":{  
         "id":888540,
         "label":"My 2nd shopping list",
         "current":false,
         "nb_reference":2
      }
   }
}
ในการแยกวิเคราะห์ไฟล์ JSON นี้ด้วยไลบรารี GSON มันเป็นเรื่องง่าย: ถ้าโครงการของคุณถูกลบล้าง
<dependency>
    <groupId>com.google.code.gson</groupId>
    <artifactId>gson</artifactId>
    <version>2.3.1</version>
</dependency>
จากนั้นใช้ตัวอย่างนี้:
import com.google.gson.Gson;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
//Read the JSON file
JsonElement root = new JsonParser().parse(new FileReader("/path/to/the/json/file/in/your/file/system.json"));
//Get the content of the first map
JsonObject object = root.getAsJsonObject().get("shopping_list").getAsJsonObject();
//Iterate over this map
Gson gson = new Gson();
for (Entry<String, JsonElement> entry : object.entrySet()) {
    ShoppingList shoppingList = gson.fromJson(entry.getValue(), ShoppingList.class);
    System.out.println(shoppingList.getLabel());
}
POJO ที่เกี่ยวข้องควรเป็นดังนี้:
public class ShoppingList {
    int id;
    String label;
    boolean current;
    int nb_reference;
    //Setters & Getters !!!!!
}
หวังว่ามันจะช่วย!