简体   繁体   中英

How Do I Pass Dynamic JSON File name using Retrofit

How do I pass Dynamic JSON file name using Retrofit

MainActivity.java:

final RestAdapter restadapter = new RestAdapter.Builder().setEndpoint("http://www.domain.com/").build();
api flowerapi = restadapter.create(api.class);

api.java:

public interface api {

    @GET("/JSONS/flowers.json")
   void getData(Callback<List<Flower>> response);

}

As you can see in my above code, I am using only single/one and only flowers.json

What If I would like to call dynamic json files based on some conditions, like in some cases I have to call flowers.json , in some cases roses.json and in some cases something.json

with the @Path annotation

 @GET("/JSONS/{name}")
 void getData(@Path("name") String name, Callback<List<Flower>> response);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM