Skip to content

Instantly share code, notes, and snippets.

@julianbonilla
Created May 24, 2012 21:18
Show Gist options
  • Save julianbonilla/2784293 to your computer and use it in GitHub Desktop.
Save julianbonilla/2784293 to your computer and use it in GitHub Desktop.
Read json from file into Gson
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import com.google.gson.Gson;
public class GsonTest {
public static void main(String[] args) throws FileNotFoundException {
String path = "PATH TO YOUR JSON FILE";
BufferedReader bufferedReader = new BufferedReader(new FileReader(path));
Gson gson = new Gson();
Object json = gson.fromJson(bufferedReader, Object.class);
System.out.println(json.getClass());
System.out.println(json.toString());
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment