use GSON lib
add this dependency in build.gradle
compile 'com.google.code.gson:gson:2.8.0'
API Services
@Headers({
"Content-Type: application/json",
"x-access-token: eyJhbGciOiJIU"
})
@POST("/api/employee/checkin")
Call<String> CHECKIN(@Body String data);
Activity Class
try {
JsonArray datas = new JsonArray();
JsonObject object = new JsonObject();
object.addProperty("dat1","1");
object.addProperty("dat2", "");
object.addProperty("dat3", "");
object.addProperty("dat4", "");
object.addProperty("dat5", "");
datas.add(object);
JsonObject req = new JsonObject();
req.addProperty("logTime", "");
req.addProperty("datas", new Gson().toJson(datas));
} catch (Exception e) {
e.printStackTrace();
}
ApiService service = retroClient.getApiService();
Call<String> login = service.CHECKIN(String.valueOf(req));
login.enqueue(new Callback<String>() {
@Override
public void onResponse(Call<String> call, Response<String> response) {
dialog.dismiss();
try {
String val = response.body();
} catch (Exception e) {
e.getMessage();
}
}
@Override
public void onFailure(Call<String> call, Throwable t) {
}
});
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…