[英]how to send/parse my below json data in android retrofit using GET call
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);
}
how can i send my brand value to above call dynamically 我如何动态地将我的品牌价值发送给上述致电
getmaptable?map_type=Model&brand=BMW
getmaptable?map_type = Model&brand =宝马
Use this: 用这个:
public interface iMakeType {
@Headers({"Content-Type:application/json"})
@GET("/getmaptable")
MakeResponse getMakeTypeData(@Query("map_type") String map_type, @Query("brand") String brand);
}
Then: 然后:
yourApi.getMakeTypeData("Model", "BMW").enqueue(...)
you can take advantage of @QueryMap from retrofit. 您可以利用改造中的@QueryMap 。
- The @QueryMap annotation expects a Map with key-value-pairs of type String . - @QueryMap注释期望Map的键值对类型为String 。 Each key which has a non-null value will be mapped and you can dynamically add your desired query parameters.
每个具有非空值的键都将被映射,您可以动态添加所需的查询参数。
public interface iMakeType {
@Headers({"Content-Type:application/json"})
@GET("/getmaptable")
MakeResponse getMakeTypeData(@QueryMap Map<String, String> map);
}
and implement it like below- 并像下面这样实现
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(…);
}
I hope, this will help you to add @Query Param Dynamically ! 希望这可以帮助您动态添加@Query Param !
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.