Skip to content

Instantly share code, notes, and snippets.

@shubham0204
Created May 1, 2019 03:49
Show Gist options
  • Save shubham0204/d02be9d1b8b5dd498c879d5828ab7872 to your computer and use it in GitHub Desktop.
Save shubham0204/d02be9d1b8b5dd498c879d5828ab7872 to your computer and use it in GitHub Desktop.
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