java - 如何转换 Hashmap到 JSONPObject
问题描述
在否决问题之前,我想把 aHashMap<String, String>
变成 a ,请注意和JSONPOject
之间的区别。我已经尝试过 new ,但它不起作用,抛出一个错误,上面写着“此处不允许使用数组初始化程序”,我该怎么做?这是我的代码,请忽略西班牙语的声明;)。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;
}
解决方案
推荐阅读
- java - 从 Cassandra 的两个不同键空间中的两个表中选择数据
- .net - 如何格式化 highcharts .NET stacklabel total
- kubernetes - 如何构建具有不同配置的多个常见容器
- c++ - 从 boost property_tree 写入 JSON 时,是否有一种简单的方法可以抑制外部“{”..“}”?
- odoo - qweb 报告自定义纸张格式输出正确,但渲染输出为 A4 大小 - Odoo
- reactjs - AcquireToken_In_Progress:登录调用期间出错 - 登录已在进行中
- r - 移动平均线似乎是使用 geom_ma 从最近的日期向后计算
- asp.net - Linq 在单个数据中获取键和多个值
- node.js - 如何将数组中的项目投影到顶层并仅获取数组中的匹配对象
- jquery - 与 jQuery“响应式标签”插件一起使用时,href 不起作用