java.lang.string类型的值html无法转换为jsonobject。我有这个代码,并尝试运行,但它给了我
的例外“org.json.JSONException:java.lang.string类型的值html无法转换为jsonobject”。
public void postTransaksi() {
loading = ProgressDialog.show(mContext, null, "Harap Tunggu...", true, false);
ApiInterface client = ApiClient.getAPIService();
String idMeridian = tvStatus.getText().toString();
String idProject = spProject.getSelectedItem().toString();
String idCategory = spCategory.getSelectedItem().toString();
String kegiatan = etKegiatan.getText().toString();
String tanggal = tvCal.getText().toString();
String nominal = etNominal.getText().toString();
String keterangan = etKeterangan.getText().toString();
String status = null;
Call<InputModel> call = client.postTransaksi(idMeridian, idProject, idCategory, kegiatan, tanggal, nominal, keterangan, status);
call.enqueue(new Callback<InputModel>() {
@Override
public void onResponse(Call<InputModel> call, Response<InputModel> response) {
if (response.isSuccessful()){
loading.dismiss();
Toast.makeText(mContext, "Berhasil menambahkan data", Toast.LENGTH_SHORT).show();
startActivity(new Intent(mContext, InsertActivity.class)
.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK));
finish();
} else {
try {
JSONObject jObjError = new JSONObject(response.errorBody().string());
Toast.makeText(InsertActivity.this, jObjError.getString("message"), Toast.LENGTH_LONG).show();
} catch (Exception e) {
Toast.makeText(InsertActivity.this, e.getMessage(), Toast.LENGTH_LONG).show();
}
}
}
@Override
public void onFailure(Call<InputModel> call, Throwable t) {
loading.dismiss();
Toast.makeText(mContext, "Koneksi internet bermasalah", Toast.LENGTH_SHORT).show();
}
});
}
服务器上的我的JSON:
{
"id_transaksi": null,
"id_meridian": "5",
"id_proyek": "2",
"kegiatan": "coba lagi",
"nominal": "100000",
"id_kategori": "1",
"tanggal": "2018-03-12",
"keterangan": "coba",
"status": null,
}
任何帮助都会得到满足。
这是我的InputModel类:
public class InputModel {
@SerializedName("id_meridian")
@Expose
private String idMeridian;
@SerializedName("id_proyek")
@Expose
private String idProyek;
@SerializedName("kegiatan")
@Expose
private String kegiatan;
@SerializedName("nomminal")
@Expose
private String nominal;
@SerializedName("id_kategori")
@Expose
private String idKategori;
@SerializedName("tanggal")
@Expose
private String tanggal;
@SerializedName("keterangan")
@Expose
private String keterangan;
@SerializedName("status")
@Expose
private Integer status;
@SerializedName("images")
@Expose
private List<Image> images = null;
public String getIdMeridian() {
return idMeridian;
}
public void setIdMeridian(String idMeridian) {
this.idMeridian = idMeridian;
}
public String getIdProyek() {
return idProyek;
}
public void setIdProyek(String idProyek) {
this.idProyek = idProyek;
}
public String getKegiatan() {
return kegiatan;
}
public void setKegiatan(String kegiatan) {
this.kegiatan = kegiatan;
}
public String getNomminal() {
return nominal;
}
public void setNomminal(String nomminal) {
this.nominal = nomminal;
}
public String getIdKategori() {
return idKategori;
}
public void setIdKategori(String idKategori) {
this.idKategori = idKategori;
}
public String getTanggal() {
return tanggal;
}
public void setTanggal(String tanggal) {
this.tanggal = tanggal;
}
public String getKeterangan() {
return keterangan;
}
public void setKeterangan(String keterangan) {
this.keterangan = keterangan;
}
public Integer getStatus() {
return status;
}
public void setStatus(Integer status) {
this.status = status;
}
public List<Image> getImages() {
return images;
}
public void setImages(List<Image> images) {
this.images = images;
}
@Override
public String toString() {
return "InputModel{" +
"id_meridian='" + idMeridian + '\'' +
", id_proyek" + idProyek + '\'' +
", kegiatan=" + kegiatan +
", nominal" + nominal +
", idKategori" + idKategori +
", tanggal" + tanggal +
", keterangan" + keterangan +
", status" + status +
", images" + images +
'}';
}
}
答案 0 :(得分:0)
您获得的响应是html类型,而不是json。请检查您的回复。