2016-03-07 70 views
3

我試着將Kotlin RxJava和retrofit2結合起來。Retrofit2和kotlin

@GET("/xxxxxxxxxxxx/{id}.json") 
fun getHotel(@Part("id") id : String) : Observable<Response<Hotel>> 

當我嘗試調用此方法(getHotels()):

var subscription = HotelsFactory.getHotelService((activity.applicationContext as App) 
      .client) 
     .getHotel(arguments.getInt("id").toString()) 
     .subscribeOn(Schedulers.computation()) 
     .observeOn(AndroidSchedulers.mainThread()) 
     .subscribe({response -> showHotels(response)}) 
     {throwable ->  throwable.printStackTrace()} 
    mSubscription.add(subscription) 

我藉此之一:

@part參數只能與多部分編碼時使用。

+0

您應該使用'@ Path'而不是'@ Part' – jturolla

回答

5

的問題是你想使用@Part註釋,你應該使用@Path註釋,只需更換它,你應該準備就緒。

@Part,如錯誤描述,應在提交多部分表單數據而不是用於修改URL時使用。