到 JSONPObject,java"/>

首页 > 解决方案 > 如何转换 Hashmap到 JSONPObject

问题描述

在否决问题之前,我想把 aHashMap<String, String> 变成 a ,请注意和JSONPOject之间的区别。我已经尝试过 new ,但它不起作用,抛出一个错误,上面写着“此处不允许使用数组初始化程序”,我该怎么做?这是我的代码,请忽略西班牙语的声明;)。JSONPOjectJSONObjectJSONPObject({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;
    }

标签: java

解决方案


推荐阅读