Android Coding

Gson 사용법 정리

오마로 2023. 8. 2. 12:29
반응형

자주 사용하는 Gson에 대한 정리 ^^

1.json을 hashmap으로 변환

String jsonString = "{\"EVENT_TYPE\":\"결과\", \"DV_CD\":\"아이디\"}";

// Create a Gson instance
Gson gson = new Gson();

// Define the type of the map (String key, String value)
Type type = new TypeToken<HashMap<String, String>>() {}.getType();

// Deserialize the JSON string to a HashMap
HashMap<String, Object> properties = gson.fromJson(jsonString, type);
반응형