1
這是用於發送和接收與鍵改造單值/陣列
一個字符串值Urls.class
public class Urls {
public static final String MAIN_URL="example.com";
}
API.class
public interface API {
@POST("user.php")
Call<MainResponse> registerUser(@Body User user);
@POST("user.php")
Call<MainResponse>loginUser(@Body User user);
@POST("contact.php")
Call<MainResponse>checkNumber(@Body Phone phone);
}
我的web服務WebService.class
public class WebService {
private static WebService instance;
private API api;
public WebService() {
OkHttpClient client = new OkHttpClient.Builder().build();
Retrofit retrofit = new Retrofit.Builder().client(client)
.addConverterFactory(GsonConverterFactory.create())
.baseUrl(Urls.MAIN_URL)
.build();
api = retrofit.create(API.class);
}
public static WebService getInstance() {
if (instance == null) {
instance = new WebService();
}
return instance;
}
public API getApi() {
return api;
}
}
MainResponse.class
public class MainResponse {
@SerializedName("status")
public int status;
@SerializedName("message")
public String message;
}
Phone.class
public class Phone {
@SerializedName("phone")
public String phone;
}
MainActivity.class
Phone phone=new Phone();
phone.phone=contactsString[0];
WebService.getInstance().getApi().checkNumber(phone).enqueue(new Callback<MainResponse>() {
@Override
public void onResponse(Call<MainResponse> call, Response<MainResponse> response) {
if (response.body().status==1){
//do something
}
}
@Override
public void onFailure(Call<MainResponse> call, Throwable t) {
}
});
我的問題是如何編輯此派填入值contactsString[]
的數組,並收到另一個陣列
這是您要發送一個數組什麼,我要求 – RealDEV
的值作爲請求並得到結果。我對嗎? – Meikiem
是的,這就是我要求 – RealDEV