티스토리 뷰

반응형

에러

retrofit Expected a string but was BEGIN_OBJECT at line 1 column 2 path $

 

원인

result를 스트링 바디로 받게 설정해놨더니 이런 에러가 났다.

 

 

해결

그래들 파일(app레벨)에 implement하고

    implementation "com.squareup.retrofit2:converter-scalars:2.1.0"

 

ScalarsConverterFactory를 추가해주면 된다. 

반드시 GsonConverterFactory위에 써줘야함!

val retrofit = Retrofit.Builder()
                .addCallAdapterFactory(RxJava2CallAdapterFactory.create())
                .addConverterFactory(ScalarsConverterFactory.create() )
                .addConverterFactory(GsonConverterFactory.create(gson))
                .baseUrl(BASE_URL)
                .build()

 

 

참고

stackoverflow.com/questions/48296987/retrofit-expected-a-string-but-was-begin-object-at-line-1-column-2-path

 

retrofit Expected a string but was BEGIN_OBJECT at line 1 column 2 path $

I'm trying to get just string request but it's give error like this Expected BEGIN_ARRAY but was BEGIN_OBJECT at line 1 column 2 path $ And my API output is like this : { "status": true, "

stackoverflow.com

 

반응형