Code example for Gson

Methods: fromJson

SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
		String json = prefs.getString("settings","");
	    if (!json.equals(""))
	    	Gson gson = new Gson();
	    	current = gson.fromJson(json, Settings.class);
	public static void load(String json)
		String previousLocation = current.location; 
		int previousWeatherStation = current.openWeatherMapStation;
		Gson gson = new Gson();
		Settings result = gson.fromJson(json, Settings.class);
		//prevents a client from posting back blank settings if it failed to load them first 
		if (!result.getName().equals(""))
Experience pair programming with AI  Get Codota for Java