首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >我用过api,但是我搞不懂如何使用改进的基本url和参数。

我用过api,但是我搞不懂如何使用改进的基本url和参数。
EN

Stack Overflow用户
提问于 2020-02-09 18:09:11
回答 1查看 29关注 0票数 0

我的接口是:

https://api.domainname.com/25/SmartService.svc/GetFundslistByPANIMEI=ODY2NzQxMDMzNDQwMjQx%0A&Fund=&APKVer=NC4zMg%3D%3D%0A&pan=QUZZUE01NzE5Qg%3D%3D%0A&Adminusername=c21hcnRzZXJ2aWNl&OS=QW5kcm9pZA%3D%3D%0A&Adminpassword=a2FydnkxMjM0JTI0

上述URL中的JSON响应如下所示

代码语言:javascript
运行
复制
{"Table":[{"Error_code":"0","Error_Message":"Success","EncryptionFlag":"N"}
],"Table1":[{"Fund_Id":"128","FN_FundDescription":"ABCD FUND"},{"Fund_Id":"178","FN_FundDescription":"XYZ FUND"},{"Fund_Id":"116","FN_FundDescription":"Pritham FUND"},{"Fund_Id":"118","FN_FundDescription":"Ram FUND"},{"Fund_Id":"130","FN_FundDescription":"Mannu FUND"}]}

我将baseurl作为mainactivity.java中的https://api.domainname/25/SmartService.svc

谁能告诉我如何调用Interface.java类中url部分的其余部分作为@GET(“");

我生成了一个pojo类,它也生成了3个类。

1个.Example.java

代码语言:javascript
运行
复制
package com.example.retrofit;

import java.util.List;
import com.google.gson.annotations.Expose;
import com.google.gson.annotations.SerializedName;

public class Example {

    @SerializedName("Table")
    @Expose
    private List<Table> table = null;
    @SerializedName("Table1")
    @Expose
    private List<Table1> table1 = null;

    public List<Table> getTable() {
        return table;
    }

    public void setTable(List<Table> table) {
        this.table = table;
    }

    public List<Table1> getTable1() {
        return table1;
    }

    public void setTable1(List<Table1> table1) {
        this.table1 = table1;
    }

}

2.Table.java

代码语言:javascript
运行
复制
package com.example.retrofit;

import com.google.gson.annotations.Expose;
import com.google.gson.annotations.SerializedName;

public class Table {

    @SerializedName("Error_code")
    @Expose
    private String errorCode;
    @SerializedName("Error_Message")
    @Expose
    private String errorMessage;
    @SerializedName("EncryptionFlag")
    @Expose
    private String encryptionFlag;

    public String getErrorCode() {
        return errorCode;
    }

    public void setErrorCode(String errorCode) {
        this.errorCode = errorCode;
    }

    public String getErrorMessage() {
        return errorMessage;
    }

    public void setErrorMessage(String errorMessage) {
        this.errorMessage = errorMessage;
    }

    public String getEncryptionFlag() {
        return encryptionFlag;
    }

    public void setEncryptionFlag(String encryptionFlag) {
        this.encryptionFlag = encryptionFlag;
    }

}

3 .Table1.java包com.example.retrofit;

代码语言:javascript
运行
复制
import com.google.gson.annotations.Expose;
import com.google.gson.annotations.SerializedName;

public class Table1 {

    @SerializedName("Fund_Id")
    @Expose
    private String fundId;
    @SerializedName("FN_FundDescription")
    @Expose
    private String fNFundDescription;

    public String getFundId() {
        return fundId;
    }

    public void setFundId(String fundId) {
        this.fundId = fundId;
    }

    public String getFNFundDescription() {
        return fNFundDescription;
    }

    public void setFNFundDescription(String fNFundDescription) {
        this.fNFundDescription = fNFundDescription;
    }

}

所以请任何人帮助我如何从剩余的url中获取参数,并将其与querymap concept.so一起使用,以便我可以在recyclerview中显示json响应。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-02-09 18:23:45

我不认为你应该使用https://api.domainname/25/SmartService.svc作为基本url。相反,您应该做的是:

进行以下更改:

基本地址:https://api.domainname/

您的“URL Part的其余部分”应该是:@GET("{numValue}/SmartService.svc")

一种可能的方法是:

代码语言:javascript
运行
复制
@GET("{numValue}/SmartService.svc")
public Call<List<Example>> getExample(
   @Path("num_value") int numValue,
   @Query("GetFundslistByPANIMEI") String panImei,
   @Query("Fund") String fund,
   @Query("APKVer") String apkVer,
   @Query("pan") String pan,
   @Query("Adminusername") String adminUsername,
   @Query("Adminpassword") String adminPassword)

这里的{numValue}是您提供的值,即25

当然,您可以使用@QueryMap Map<String, String>。请务必查看官方Retrofit Documentation了解更多信息。

注意:另外,请确保getExample()的返回符合您的预期。我可能误解并使用了Call<List<Example>>

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/60135459

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档