gson 转Map int 变double

gson = new GsonBuilder()
                    .registerTypeAdapter(
                            new TypeToken>() {
                            }.getType(),
                            new JsonDeserializer>() {
                                @Override
                                public TreeMap deserialize(
                                        JsonElement json, Type typeOfT,
                                        JsonDeserializationContext context) throws JsonParseException {

                                    TreeMap treeMap = new TreeMap<>();
                                    JsonObject jsonObject = json.getAsJsonObject();
                                    Set> entrySet = jsonObject.entrySet();
                                    for (Map.Entry entry : entrySet) {
                                        Object ot = entry.getValue();
                                        if (ot instanceof JsonPrimitive) {
                                            treeMap.put(entry.getKey(), ((JsonPrimitive) ot).getAsString());
                                        } else {
                                            treeMap.put(entry.getKey(), ot);
                                        }
                                    }
                                    return treeMap;
                                }
                            }).create();
TreeMap map = null;
            Type typeToken = new TypeToken>() {
            }.getType();
            map = gson.fromJson(gsonString, typeToken);

你可能感兴趣的:(gson 转Map int 变double)