Created
May 1, 2019 03:49
-
-
Save shubham0204/d02be9d1b8b5dd498c879d5828ab7872 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private fun loadJSONFromAsset(filename : String? ): String? { | |
var json: String? = null | |
try { | |
val inputStream = context!!.assets.open(filename ) | |
val size = inputStream.available() | |
val buffer = ByteArray(size) | |
inputStream.read(buffer) | |
inputStream.close() | |
json = String(buffer) | |
} | |
catch (ex: IOException) { | |
ex.printStackTrace() | |
return null | |
} | |
return json | |
} | |
val jsonObject = JSONObject( loadJSONFromAsset( "word_dict.json" ) ) | |
val iterator : Iterator<String> = jsonObject.keys() | |
val data = HashMap< String , Int >() | |
while ( iterator.hasNext() ) { | |
val key = iterator.next() | |
data.put( key , jsonObject.get( key ) as Int ) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment