2017-10-17 45 views
0
public interface iMakeType { 
    @Headers({"Content-Type:application/json"}) 
    @GET("/getmaptable?map_type=Model&brand=(here i need to pass my value dynamically)") 
    MakeResponse getMakeTypeData(@Query("map_type")String map_type); 
} 

如何將我的品牌價值發送到上述呼叫動態如何發送/使用GET調用

getmaptable?map_type =型號&品牌解析我下面的JSON數據在android系統的改造= BMW

回答

0

使用此:

public interface iMakeType { 
    @Headers({"Content-Type:application/json"}) 
    @GET("/getmaptable") 
    MakeResponse getMakeTypeData(@Query("map_type") String map_type, @Query("brand") String brand); 
} 

然後:

yourApi.getMakeTypeData("Model", "BMW").enqueue(...) 
+1

非常感謝你的傢伙! –

0

您可以充分利用@QueryMap改造。

-@QueryMap註釋願與鍵 - 值對類型字符串的地圖。每個具有非空值的鍵將被映射,您可以動態添加所需的查詢參數。

public interface iMakeType { 
    @Headers({"Content-Type:application/json"}) 
    @GET("/getmaptable") 
    MakeResponse getMakeTypeData(@QueryMap Map<String, String> map); 
} 

,並實現它就像如下─

private MakeResponse makeType() { 
    Map<String, String> data = new HashMap<>(); 
    data.put("map_type", "Model"); 
    data.put("brand", "BMW"); 


    MakeResponse call = api.getMakeTypeData(data); 
    call.enqueue(…); 

} 

我希望,這將幫助你添加@Query帕拉姆動態!