Code example for Set

Methods: add

0
import org.json.JSONObject; 
 
public class JSONUtil { 
    static Set<Class> knownTypes = new HashSet<Class>();
    static { 
        knownTypes.add(String.class);
        knownTypes.add(Double.class);
        knownTypes.add(Integer.class);
        knownTypes.add(Float.class);
        knownTypes.add(Long.class);
        knownTypes.add(Boolean.class);
    } 
 
    public static String toJsonString(Object obj) {
        Map<String, Object> map = getMap(obj);
        JSONObject jsonObject = toJSONObject(map);
        return jsonObject.toString();
    } 
 
    public static Map<String, Object> getMapFromJson(String str) {
        return getRawRecord(fromJsonString(str));