我有一個包含這個值的字符串:得到字符串值和的值複製到POJO屬性:JAVA
String verifyPaymentDetails = "{
2298597={mihpayid=403993715508098532, request_id=NULL, bank_ref_num=NULL, amt=53.77, disc=0.00, mode=CC, PG_TYPE=AXIS, card_no=512345XXXXXX2346, name_on_card=emu, udf2=0, addedon=2013-06-03 17:34:42, status=failure, unmappedstatus=failed, Merchant_UTR=NULL, Settled_At=NULL},
6503939={mihpayid=Not Found, status=Not Found}
}"
,我想從上面的字符串提取值,並將其存儲如下所示:
重點將是關鍵mihpayid=403993715508098532, request_id=NULL, bank_ref_num=NULL, amt=53.77, disc=0.00, mode=CC, PG_TYPE=AXIS, card_no=512345XXXXXX2346, name_on_card=emu, udf2=0, addedon=2013-06-03 17:34:42, status=failure, unmappedstatus=failed, Merchant_UTR=NULL, Settled_At=NULL
Map<String,Item> tag = new HashMap<String,VerifyPaymentRO>();
2298597
和價值觀,這就是我VerifyPaymentRO
public class VerifyPaymentRO {
private String mihpayid;
private String request_id;
private String bank_ref_num;
private String amt;
private String disc;
private String mode;
private String PG_TYPE;
private String card_no;
private String name_on_card;
private String udf2;
private String addedon;
private String status;
private String unmappedstatus;
private String Merchant_UTR;
private String Settled_At;
public String getMihpayid() {
return mihpayid;
}
public void setMihpayid(String mihpayid) {
this.mihpayid = mihpayid;
}
public String getRequest_id() {
return request_id;
}
public void setRequest_id(String request_id) {
this.request_id = request_id;
}
public String getBank_ref_num() {
return bank_ref_num;
}
public void setBank_ref_num(String bank_ref_num) {
this.bank_ref_num = bank_ref_num;
}
public String getAmt() {
return amt;
}
public void setAmt(String amt) {
this.amt = amt;
}
public String getDisc() {
return disc;
}
public void setDisc(String disc) {
this.disc = disc;
}
public String getMode() {
return mode;
}
public void setMode(String mode) {
this.mode = mode;
}
public String getPG_TYPE() {
return PG_TYPE;
}
public void setPG_TYPE(String pG_TYPE) {
PG_TYPE = pG_TYPE;
}
public String getCard_no() {
return card_no;
}
public void setCard_no(String card_no) {
this.card_no = card_no;
}
public String getName_on_card() {
return name_on_card;
}
public void setName_on_card(String name_on_card) {
this.name_on_card = name_on_card;
}
public String getUdf2() {
return udf2;
}
public void setUdf2(String udf2) {
this.udf2 = udf2;
}
public String getAddedon() {
return addedon;
}
public void setAddedon(String addedon) {
this.addedon = addedon;
}
public String getStatus() {
return status;
}
public void setStatus(String status) {
this.status = status;
}
public String getUnmappedstatus() {
return unmappedstatus;
}
public void setUnmappedstatus(String unmappedstatus) {
this.unmappedstatus = unmappedstatus;
}
public String getMerchant_UTR() {
return Merchant_UTR;
}
public void setMerchant_UTR(String merchant_UTR) {
Merchant_UTR = merchant_UTR;
}
public String getSettled_At() {
return Settled_At;
}
public void setSettled_At(String settled_At) {
Settled_At = settled_At;
}
}
那麼如何從字符串中獲取id和id的值,並將這些值複製到POJO並將它們存儲爲一個HashMap中的id和object?
是否有辦法爲這個春天也蠻好
您試圖將字符串反序列化爲對象。如果字符串是由您定義的,最好使用像JSON或XML這樣的通用序列化來執行這些操作並自動化該過程。無論如何,你的請求可以使用正則表達式甚至StringTokenizer來執行,但是相當長......它根本與Spring沒有關係。 – logoff
@logoff你會給我一些樣品請 –
如果這是一個JSON,它會一直很簡單!我認爲提取每個值並手動設置它們是唯一的方法。 – SudoRahul