-
JsonReader와 함게 사용
import java.io.FileReader; import java.io.FileNotFoundException; import java.util.Map; import java.util.Set; import com.google.gson.Gson; import com.google.gson.JsonElement; import com.google.gson.JsonObject; import com.google.gson.stream.JsonReader; Gson gson = new Gson();try { JsonReader rd = new JsonReader(new FileReader(filepath)); JsonObject obj = gson.fromJson(rd, JsonObject.class); System.out.println("\"phone\": " + obj.get("phone")); Set<Map.Entry<String, JsonElement>> element = obj.entrySet(); for (Map.Entry<String, JsonElement> entry : element) { System.out.println("key: " + entry.getKey()); System.out.println("val: " + entry.getValue() + "\n"); } } catch (FileNotFoundException e) { System.out.println("file does not exist"); }
'Java' 카테고리의 다른 글
HttpURLConnection (0) 2022.08.07 RxJava Observable emitter Ex (0) 2022.08.06 RxJava (0) 2022.08.05 JSP에서 json 출력 (0) 2022.08.04 Java String 문자열 변환 UTF-8 (0) 2021.11.12 Java예제 - 문자열을 받아서 계산(계산기) (0) 2020.07.16 Java - String split (0) 2020.07.16 Java 변수(variable) (0) 2020.07.10