直接上main方法
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
....
....
public static void main(String[] args) {
String ret = "{\"ackMode\":\"1\",\"apdus\":[{\"command\" : \"8482000010E01474019B363188201067184638AF61\",\"index\" : 0,\"swe1\" : \"90\",\"swe2\" : \"00\"},{\"command\" : \"80500000081122334455667788\",\"index\" : 1,\"swe1\" : \"90\",\"swe2\" : \"00\"}],\"cardNo\" : \"6214671540001271844\",\"currentStep\" : \"3\",\"description\" : \"成功\",\"nextStep\" : \"\",\"printData\" : \"\",\"statusCode\" : \"0\",\"totalStep\" : \"7\"}";
JSONObject obj = JSONArray.parseObject(ret);
TestResp resp = JSONObject.toJavaObject(obj, TestResp.class);
System.out.println(resp.getAckMode());
}
需要转换成的实体类
class TestResp {
private String statusCode; // 响应状态码 成功0000,失败9999或其他状态码
private String description; // 返回信息
private String ackMode; // 指令执行方式 0:接触;1:非接
private List<Apdu> apdus; // Apdu对象列表
private String cardNo; // 卡号
private String printData; // 卡片打印数据,包括磁条数据
private String printConf; // 卡片打印参数
private String currentStep; // 当前步骤 与请求一致
private String nextStep; // 下一步骤 作为下一次请求currentStep的值,返回-1时为最后一步无需再次请求
private String totalStep; // 总步骤数
public String getStatusCode() {
return statusCode;
}
public void setStatusCode(String statusCode) {
this.statusCode = statusCode;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public String getAckMode() {
return ackMode;
}
public void setAckMode(String ackMode) {
this.ackMode = ackMode;
}
public List<Apdu> getApdus() {
return apdus;
}
public void setApdus(List<Apdu> apdus) {
this.apdus = apdus;
}
public String getCardNo() {
return cardNo;
}
public void setCardNo(String cardNo) {
this.cardNo = cardNo;
}
public String getPrintData() {
return printData;
}
public void setPrintData(String printData) {
this.printData = printData;
}
public String getPrintConf() {
return printConf;
}
public void setPrintConf(String printConf) {
this.printConf = printConf;
}
public String getCurrentStep() {
return currentStep;
}
public void setCurrentStep(String currentStep) {
this.currentStep = currentStep;
}
public String getNextStep() {
return nextStep;
}
public void setNextStep(String nextStep) {
this.nextStep = nextStep;
}
public String getTotalStep() {
return totalStep;
}
public void setTotalStep(String totalStep) {
this.totalStep = totalStep;
}
}
class Apdu {
private String index; // 指令执行顺序
private String command; // 需执行的指令
private String swe1; // 执行指令期望返回swe1
private String swe2; // 执行指令期望返回swe2
public String getIndex() {
return index;
}
public void setIndex(String index) {
this.index = index;
}
public String getCommand() {
return command;
}
public void setCommand(String command) {
this.command = command;
}
public String getSwe1() {
return swe1;
}
public void setSwe1(String swe1) {
this.swe1 = swe1;
}
public String getSwe2() {
return swe2;
}
public void setSwe2(String swe2) {
this.swe2 = swe2;
}
}