am new in android studio " kotlin " , am try to get information from url data json , content JSONObject and JSONArray , my code Working fine with JSONObject , but i still have problem withe JSONArray .
this is my code for any one can help me to how can get JSONArray from my url
fun buclick(view:View){
val flightSearch=editText2.text.toString()
val url="xxxxxxx-flight=$flightSearch"
MyAsyncTask().execute(url)
}
inner class MyAsyncTask:AsyncTask<String,String,String>(){
override fun onPreExecute() {
super.onPreExecute()
}
override fun doInBackground(vararg p0: String?): String {
//تمرير بيانات هنا
try {
val url=URL(p0[0])
val urlConnect = url.openConnection() as HttpURLConnection
urlConnect.connectTimeout=500
val dataJsonAsString=convertStreanToString(urlConnect.inputStream)
publishProgress(dataJsonAsString)
}catch (ex:Exception){
}
return ""
}
override fun onProgressUpdate(vararg values:String?) {
val json=JSONObject(values[0])
val query= json.getJSONObject("identification")
val sunrise=query.getString("id")
flighttext.text="sunrise time" + sunrise
}
override fun onPostExecute(result: String?) {
super.onPostExecute(result)
}
fun convertStreanToString(inputStream:InputStream):String{
val bufferReader = BufferedReader(InputStreamReader(inputStream))
var line:String
var allstring:String=""
try {
do {
line=bufferReader.readLine()
if(line!=null)
allstring+=line
}while (line!=null)
bufferReader.close()
}catch (ex:Exception){}
return allstring
}
}
//مالنا شغل ببيها
override fun onBackPressed() {
if (drawer_layout.isDrawerOpen(GravityCompat.START)) {
drawer_layout.closeDrawer(GravityCompat.START)
} else {
super.onBackPressed()
}
}