如何将Hashmap <string,string =“”>转换为JSONPObject

时间:2018-10-05 09:44:49

标签: java

我想将HashMap<String, String>变成JSONPOject,然后再对问题笔记进行否决,JSONPOjectJSONObject之间的区别。我已经尝试过像新的JSONPObject({HasMap<String, String>})一样,但是它不起作用,并抛出一个错误消息:“此处不允许使用数组初始化程序”,我该怎么办?这是我的代码,请忽略西班牙语;)的声明。

代码

public JSONPObject getOnlyDistritosTarificacion(String string) {

        List<Map<String, Object>> filas_distritos = null;
        HashMap<String, String> distrito = new HashMap<>();

        filas_distritos = jdbcTemplate.queryForList(CONSULTA_SOLO_DISTRITOS, new Object[]{string, string});

        if ((filas_distritos != null) && (!filas_distritos.isEmpty()) || (filas_distritos.size() != 0)) {
            Map<String, Object> row = filas_distritos.get(0);
            distrito.put("distrito", (String) row.get("DISTRITO"));
            distrito.put("inicio", (String) row.get("INICIO"));
            distrito.put("fin", (String) row.get("FIN"));
            distrito.put("mensaje", "El n&uacute;mero consultado (" + string + ") ya pertenece a un Distrito de Tarificaci&oacute;n.");


            JSONPObject jsonpObject = new JSONPObject({distrito});
        }else {
            distrito.put("mensaje", "El n&uacute;mero consultado (" + string + ") no pertenece a un Distrito de Tarificaci&oacute;n.");
        }
        return distrito;
    }

0 个答案:

没有答案