I am using below code. and with getting this output.
output
Header : {"id" : 12345, "value" : "123", "person" : "1"}
CDD : {"CDDid" : 3456 }
But my required output like this below:
Header id 12345
Header value 123
Header Person 1
CDD CDDid 3456
import org.json.JSONException;
import org.json.JSONObject;
public class Test{
private static HashMap<String, Object> getHashMapFromJson(String json) throws JSONException {
HashMap<String, Object> map = new HashMap<String, Object>();
JSONObject jsonObject = new JSONObject(json);
for (Iterator<String> it = jsonObject.keys(); it.hasNext();) {
String key = it.next();
map.put(key, jsonObject.get(key));
}
return map;
}
public static void main(String[] args ){
String json = " { \"Header\" : {\"id\" : 12345, \"value\" : \"123\", \"person\" : \"1\"} ,\"CDD\" : {\"CDDid\" : 3456 }}";
try {
HashMap<String, Object> map = getHashMapFromJson(json);
for (String key : map.keySet()) {
System.out.println(key + ": " + map.get(key));
}
} catch (JSONException e) {
System.out.println("JsonTest" + "Failed parsing " + json + e);
}
}
}