首页 > 解决方案 > 如何将数据解析为来自其他类的链接 api

问题描述

我是这里的新手。我想问一下是否可以在改造链接中添加固定值的数据。

这是我的代码:(这里我有一个值从我的模块中获取我的用户 ID。)

public class ScheduleModule extends Fragment {
public static String qqst;
View inflatedView = null;

@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {

    inflatedView = inflater.inflate(R.layout.fragment_schedule_module, container, false);

    ggst = Settings.Secure.getString(getContext().getContentResolver(),
            Settings.Secure.ANDROID_ID);

我想在我的api上添加这个。通过将数据传递给链接但它不起作用..

public interface API {

  @GET("api/Database/GetSchedule? 
  serialNumber="+"Schedule.ggst")
  Call<List<ScheduleDetails>> getSchedData();
}

Schedule.ggst无法将我模块中的数据链接到 api 。但在我的情况下,这是我喜欢做的,以便在每个设备中都有一个唯一的 id 访问我的自定义 api。

这是我想访问的示例数据:

api/Database/GetSchedule?serialNumber=5d2a2dd4c787e116

标签: androidapiretrofit2

解决方案


我认为您可以使用如下查询参数

@GET("api/Database/GetSchedule)
Call<List<ScheduleDetails>> getSchedData(@Query("serialNumber") int serialNumber);

并这样称呼它

APIService.getSchedData(ggst);

推荐阅读