Skip to content

Instantly share code, notes, and snippets.

@afarber
Created April 5, 2017 17:59
Show Gist options
  • Select an option

  • Save afarber/f4038fee536464feeaa0aefff8d43c43 to your computer and use it in GitHub Desktop.

Select an option

Save afarber/f4038fee536464feeaa0aefff8d43c43 to your computer and use it in GitHub Desktop.
package de.afarber.mavenproject1;
import com.google.gson.Gson;
import java.util.Map;
public class Main {
public static void main(String[] args) {
String str = "{\"Chapter\": \"5.2\",\n" +
" \"Title\": \"Hello\",\n" +
" \"Text\": \"Sentence 1. Sentence 2.\"}";
Gson gson = new Gson();
Map map = gson.fromJson(str, Map.class);
System.out.println("Chapter: " + map.get("Chapter"));
System.out.println("Title: " + map.get("Title"));
System.out.println("Text: " + map.get("Text"));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment