I have a complex string which I need to split two times by delimiters '&' and '=' respectively. Then I need to set the values in Java POJO class.I need values like 2020-08-11+15%3A11%3A49 to be set for requestTimestamp field in pojo, 0036 in channelResponseCode..... Like this for all fields. Due to for each all values are getting set for one field. Please help. My code as follows:
public static void main(String[] args) {
String strMain = "request_timestamp=2020-08-11+15%3A11%3A49&channel_response_code=0036&channel_response_desc=Payment+is+cancelled.&sub_merchant_list=";
String arrSplit[] = strMain.split("&");
// [request_timestamp=2020-08-11+15%3A11%3A49, channel_response_code=0036, channel_response_desc=Payment+is+cancelled.,_4=, user_defined_5=, .....]
// System.out.println(Arrays.toString(arrSplit));
Payment p = new Payment();
for (String s : arrSplit) {
String[] t =s.split("=");
System.out.println(Arrays.toString(t));
if(t.length >1) {
p.setRequest_timestamp(t[1]);
}
else { p.setRequest_timestamp(""); }
System.out.println("Hiii"+p.getRequest_timestamp());
}
}