Java 将JSON响应映射到相应的POJO
当从json获得响应时,我的项目有问题 这是我的JSON结构Java 将JSON响应映射到相应的POJO,java,android,json,gson,Java,Android,Json,Gson,当从json获得响应时,我的项目有问题 这是我的JSON结构 { "RC": "00", "FakturPengajuan": "PO201901310000000007", "Plafond": "1,000,000.00", "Pokok": "500,000.00", "Bunga": "10,000.00", "TotalBayar": "510,000.00", "JT": { "1": { "Ke": 1, "JatuhTempo": "28
{
"RC": "00",
"FakturPengajuan": "PO201901310000000007",
"Plafond": "1,000,000.00",
"Pokok": "500,000.00",
"Bunga": "10,000.00",
"TotalBayar": "510,000.00",
"JT": {
"1": {
"Ke": 1,
"JatuhTempo": "28 Februari 2019",
"Pokok": "500,000.00",
"Bunga": "10,000.00",
"Jumlah": "510,000.00",
"BakiDebet": "500,000.00"
},
"2": {
"Ke": 2,
"JatuhTempo": "31 Maret 2019",
"Pokok": "500,000.00",
"Bunga": "10,000.00",
"Jumlah": "510,000.00",
"BakiDebet": "0.00"
}
}
}
这是我的应答码
@Override
public void onFinish(String cResponse) {
String cError = null;
if (cResponse != null){
try{
Response response = gson.fromJson(cResponse,Response.class);
if (response != null && response.getRC() != null){
if (response.getRC().equals("00")){
}else cError = response.getMSG();
}else{
cError = "Error";
}
}catch (Exception e){
cError = "Error" + e.getMessage();
FuncApp.showLog("Response " + e.getMessage());
}
}else cError = "Gagal";
if (cError != null)
new FuncApp.OkNoDialog(getActivity(),"Gagal Aktivasi",cError ,null,"OK").setOnFinish(new FuncApp.OkNoDialog.ButtonClick() {
@Override
public void onClick(Boolean isOKButton) {
}
});
funcApp.closeProgresDialog();
}
这是我的响应getter和setter,不是全部,只是我使用的所有变量
public class Response {
private String RC;
private String FakturPengajuan, Plafond, Pokok, Bunga, TotalBayar;
private String[] JT;
public Response(){}
}
我在得到响应时遇到了这个错误,代码应该是什么
java.lang.IllegalStateException: Expected BEGIN_OBJECT but was STRING at line 1 column 1 path $
POJO类
Response
有一些无效的结构字段JT
不是数组,应该有getter和setter
public class Response {
private String RC;
private String FakturPengajuan, Plafond, Pokok, Bunga, TotalBayar;
private Map<String,MapValue> JT;
public Response(){}
}
当发布代码或在本例中为JSON数据时,请确保任何试图提供帮助的人都可以在重新创建问题时轻松使用它。谢谢。我已经在响应类中完成了getter和setter,并且已经将JT更改为Map,但是仍然无法使用stacktrace处理相同的errorUpdate错误,也无法在@RPH再次验证json
public class MapValue {
private int Ke;
private String JatuhTempo;
private String Pokok;
private String Bunga;
private String Jumlah;
private String BakiDebet;
}