gson 解析 時間類型

 GsonBuilder builder = new GsonBuilder();

// Register an adapter to manage the date types as long values

 builder.registerTypeAdapter(Date.class, new JsonDeserializer<Date>() {
                        public Date deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
                            return new Date(json.getAsJsonPrimitive().getAsLong());
                        }
                    });

 Gson gson = builder.create();

 WebDynamic webDynamic = gson.fromJson(json, WebDynamic.class);

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章