我想将HashMap<String, String>
变成JSONPOject
,然后再对问题笔记进行否决,JSONPOject
和JSONObject
之间的区别。我已经尝试过像新的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úmero consultado (" + string + ") ya pertenece a un Distrito de Tarificación.");
JSONPObject jsonpObject = new JSONPObject({distrito});
}else {
distrito.put("mensaje", "El número consultado (" + string + ") no pertenece a un Distrito de Tarificación.");
}
return distrito;
}