JSONObject has following constructor
public JSONObject(Map map) {
super(map);
}
This means you cannot create JSONObject, passing String in consctructor. But you can using map
Map<String, String> map = new LinkedHashMap<>();
map.put("phonetype","N95");
map.put("cat", "WP");
JSONObject jso = new JSONObject(map);
get method has signature
public V get(Object key)
This means that if you want to get map, value should be Map generic. For example
Map<String, String> map = new LinkedHashMap<>();
map.put("phonetype","N95");
map.put("cat", "WP");
Map<String, Map> toConstructor = new LinkedHashMap() {{
put("map", map);
}};
JSONObject jso = new JSONObject(toConstructor);
LinkedHashMap h = (LinkedHashMap) jso.get("map");
System.out.println(h);
In your case you try to cast String to LinkedHashMap, so ClassCastException was thrown