I tried few days to get this done. but could`t .
What i want is Traverse any given JSON and put Key and Value pair into a map. As a sample consider this JSON
String test = {
"RechargeRequest":{
"RechargeSerialNo":"2645",
"RechargeChannelID":"3",
"RechargeObj":{
"SubAccessCode":{
"PrimaryIdentity":"763500001"
}
},
"RechargeInfo":{
"CashPayment":[
{
"Amount":"30"
}
]
}
}
}
What i have tried so far
JSONObject jsonObj = new JSONObject(test);
Iterator<String> keys = jsonObj.keys();
Map<String,String> map = new HashMap<>();
while(keys.hasNext()) {
String key = keys.next();
if (jsonObj.get(key) instanceof JSONObject) {
}else if(jsonObj.get(key) instanceof JSONArray){
}else{
}
}
Maps value should be like ( "RechargeChannelID","3") ( "Amount":"30")
Can anybody help me please?
Thanks,