안드로이드/코틀린

[Android Studio]Response<ResponseBody> JSON 결과값 받기 코틀린 return response kotlin

eqrw105 2021. 4. 22. 00:13

[Android Studio]Response<ResponseBody> JSON 결과값 받기 코틀린 return response kotlin

 

open fun response_ui(response: Response<ResponseBody>){
        //JSON 형태의 문자열 타입
        val str = response.body()!!.string() as String

        try{
            val jsonArray = JSONArray(str)
            for (i in 0 until jsonArray.length()){
                val jsonObject = jsonArray.getJSONObject(i)

                Log.d("field value => ",jsonObject.get("filed_name").toString())
            }
        }catch (e: Exception){
            e.printStackTrace()
        }

    }