안녕하세요
firebase Realtime DB를 활용한 안드로이드 앱을 공부하고 있습니다.
Retrofit을 사용해서 db를 받아올 때...
"Expected BEGIN_ARRAY but was STRING at line 2 column 1 path$"의 오류가 뜨는데
이틀을 검색해도 해결방법을 모르겠어서 질문드립니다.. 제발 도와주십시오...ㅠㅠㅠㅠ
위 서버에서 특정 값을 가져오는 처리를 진행하면
[
{
"name": "테스트0501-45",
"type": "default"
},
{
"name": "테스트0501-3",
"type": "default"
},
{
"name": "thelatest saved one",
"type": "default"
},
{
"name": "테스트45",
"type": "default"
},
{
"name": "dupleCheck23",
"type": "default"
},
{
"name": "ffff",
"type": "default"
},
{
"name": "두",
"type": "default"
}
]
위와 같은 형태의 Json 형식의 데이터를 안드로이드로 보내줍니다.
API interface 입니다.
@GET("/loadCustomers")
fun loadCustomers(
@Query("type") type: String,
@Query("keyword") keyword: String,
@Query("type2") type2: String,
@Query("keyword2") keyword2: String,
): Call<ArrayList<loadCustomersResponse>>
Response class입니다.
@Keep
data class loadCustomersResponse (
val testArray : ArrayList<Customer>
)
data class Customer(
val key : String,
val name: String,
val type: String
)
Api클래스의 메서드 입니다.
class Api {
companion object {
val client = OkHttpClient.Builder()
.connectTimeout(1, TimeUnit.MINUTES)
.readTimeout(10, TimeUnit.SECONDS)
.writeTimeout(10, TimeUnit.SECONDS)
.build()
val gson = GsonBuilder().setLenient().create()
val retrofit = Retrofit.Builder()
.baseUrl("https://us-central1-today-s-eyebrow-kt-ver.cloudfunctions.net/")
.addConverterFactory(GsonConverterFactory.create(gson))
.client(client)
.build()
}
fun loadCustomers(
type: String, keyword: String,
type2: String, keyword2: String, callback: (Boolean, Any?) -> Unit,
) {
retrofit.create(FirebaseApi::class.java).loadCustomers(type, keyword, type2, keyword2)
.enqueue(object : Callback<ArrayList<loadCustomersResponse>> {
override fun onResponse(
call: Call<ArrayList<loadCustomersResponse>>,
response: Response<ArrayList<loadCustomersResponse>>,
) {
callback(true, response.body())
}
override fun onFailure(call: Call<ArrayList<loadCustomersResponse>>, t: Throwable) {
callback(false, t.message)
}
})
}
}
선생님들 장문의 질문을 읽어주셔서 감사합니다.
저의 구글링의 미숙함도 있겠지만...
제 선에서는 최선을 다했음에도 답을 못구했기에
먼저 길을 걸어가신 선생님들의 지혜를 구합니다..
감사합니다.