For example, we have a BufferedReader reader, associated with the json file through InputStreamReader. To get a file data we can do this:
Select an option, then click Submit answer.
-
○
var line: String? try {
while (reader.readLine().also { line = it } != null) { builder.append(line)
}
val json = JSONObject(builder.toString()) return json
} catch (exception: IOException) { exception.printStackTrace() } catch (exception: JSONException) { exception.printStackTrace()
} -
○
var line: JSONObject ? try {
while (reader.readJSONObject ().also { line = it } != null) { builder.append(line)
}
val json = JSONObject(builder.toString()) return json
} catch (exception: IOException) { exception.printStackTrace() } catch (exception: JSONException) { exception.printStackTrace()
} -
○
var line: String?
try {
while (reader.readLine().also { line = it } != null) { builder.append(line)
}
val json = JSONObject(builder.toString()) return json
} catch (exception: RuntimeException) { exception.printStackTrace()
} catch (exception: ArrayIndexOutOfBoundsException) { exception.printStackTrace()
}