// Map -> JSON
JSONObject jsonMap = JSONObject.fromObject(map);

// List -> Map -> JSON
JSONArray listJson = JSONArray.fromObject(list);

// XML String -> JSON
String xml = "
ddakker100
ab
"; JSONObject json = (JSONObject) new XMLSerializer().read(xml); System.out.println(json); JSONObject header = (JSONObject) json.get("header"); System.out.println("header: " + header); System.out.println(((JSONObject)json.get("header")).get("name")); JSONArray list = (JSONArray) json.get("list"); System.out.println("list: " + list); System.out.println("list: " + list.size()); for( int i=0; i<list.size(); i++ ){ System.out.println("list[" + i + "]: " + list.getJSONObject(i).get("friend")); }

+ Recent posts