dcsimg
 

Submitted by: Octavia Anghel(octaviaanghel@gmail.com)

Monday Apr 13th 2020 by Octavia Anghel

Language: Java, Expertise: Intermediate: See an example of how to read a file via GSON.

The following example reads a JSON file via JSON:

// create Gson instance
Gson gson = new Gson();

// create a Reader
Reader reader = Files.newBufferedReader(Paths.get("myfile.json"));

// JSON file to map
Map map = gson.fromJson(reader, Map.class);

// print map
for (Map.Entry entry : map.entrySet()) {
   System.out.println(entry.getKey() + "=" + entry.getValue());
}

// close reader
reader.close();
Home
Mobile Site | Full Site