public static CountryList getCountries ( Context context ) { if ( mCountries != null ) { return mCountries ; } mCountries = new CountryList ( ) ; try { JSONArray countries = new JSONArray ( getJsonFromRaw ( context , R . raw . countries ) ) ; for ( int i = 0 ; i < countries . length ( ) ; i ++ ) { try { JSONObject country = ( JSONObject ) countries . get ( i ) ; mCountries . add ( new Country ( country . getString ( "name" ) , country . getString ( "iso2" ) , country . getInt ( "dialCode" ) ) ) ; } catch ( JSONException e ) { e . printStackTrace ( ) ; } } } catch ( JSONException e ) { e . printStackTrace ( ) ; } return mCountries ; }
Import CountryList from RAW resource