Иметься хостинг, который в качестве ответа генерирует json.
http:// example.com/get-json/getJsonPosts.php?2
где ?2 - id поста.
У меня не получается в @Get
передать параметр.
interface Api {
@GET("getJsonPosts.php?{id}")
fun loadtPost(@Path("id") groupId: Int): Observable<ArrayList<Card>>
}
Реализация
override fun uploadData() {
var api : Api? = null
api = MyApplication().connectServer()
api!!.loadtPost(10) // Передаю параметр
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe({ e ->
recyclerView.adapter!!.notifyItemInserted(cards.size - 1)
for (i in 0 until e.size) {
cards.add(Card(e[i].photoUrl,
e[i].title,
e[i].date,
e[i].description,
e[i].photoUrl,
e[i].likeCaunt))
}
})
}
Получаю ошибку
java.lang.IllegalArgumentException: URL query string "{id}" must not have replace block. For dynamic query parameters use @Query.
Пробую теперь так
interface Api {
@GET("getJsonPosts.php?")
fun loadtPost(@Query("") groupId: Int): Observable<ArrayList<Card>>
}
Получаю ошибку
io.reactivex.exceptions.OnErrorNotImplementedException: Use JsonReader.setLenient(true) to accept malformed JSON at line 1 column 1 path $
Возможно мне нужно запрос реализовать так:
http:// example.com/get-json/getJsonPosts.php?id=2