das ist meine Web-Service für das Senden und einen String-Wert mit SchlüsselRetrofit Einzelwert/array
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);
}
Empfang WebService.klasse
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) {
}
});
Meine Frage ist, wie diese bearbeiten ein Array mit Werten contactsString[]
und erhalten
das ist, was für – RealDEV
Ich bitte Sie ein Array senden möchten von Werten als Anfrage und bekomme das Ergebnis. habe ich recht? – Meikiem
ja, das ist, was ich frage – RealDEV