我用过 api 但对如何采用基数 url 和使用改造的参数感到困惑
i have used api but having a confusion how to take base url and the parameters using retrofit
我的 api 是:
上面的JSON回复URL如下
{"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"}]}
我在 mainactivity.java
中将 baseurl 设为 https://api.domainname/25/SmartService.svc
任何人都可以告诉我如何调用 Interface.java class 中 url 部分的其余部分作为 @GET(" ");
我生成了一个 pojo classes,它也生成了 3 个 classes。
1 .Example.java
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
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;
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 响应。
我认为你不应该使用 https://api.domainname/25/SmartService.svc
作为基础 url。你应该做的是:
进行以下更改:
基础 URL : https://api.domainname/
您的 "Rest of the URL Part" 应该是:@GET("{numValue}/SmartService.svc")
一种可能的方法:
@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()
的 return 是您所期望的。我可能误解并使用了 Call<List<Example>>
.
我的 api 是:
上面的JSON回复URL如下
{"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"}]}
我在 mainactivity.java
中将 baseurl 设为 https://api.domainname/25/SmartService.svc任何人都可以告诉我如何调用 Interface.java class 中 url 部分的其余部分作为 @GET(" ");
我生成了一个 pojo classes,它也生成了 3 个 classes。
1 .Example.java
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
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;
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 响应。
我认为你不应该使用 https://api.domainname/25/SmartService.svc
作为基础 url。你应该做的是:
进行以下更改:
基础 URL : https://api.domainname/
您的 "Rest of the URL Part" 应该是:@GET("{numValue}/SmartService.svc")
一种可能的方法:
@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()
的 return 是您所期望的。我可能误解并使用了 Call<List<Example>>
.