android - 发送带键的 JSON 数组
问题描述
my output "abc":[{"1":1,"2":2,"3":1,"4":2,"5":1,"6":2,"7":1,"8":2,"9":1,"10":2,"11":1}]
//mycode
JSONArray jsonArray = new JSONArray();
JSONObject jsonObject = new JSONObject();
for(QuizAttempt order_product:products){
//jsonArray.put(order_product.getAns());
jsonObject.put(order_product.getId(),order_product.getAns());
}
//jsonObject.put()
jsonArray.put(jsonObject);
paramObject.put("abc",jsonArray);
如上所示,我出去了,上面是我的代码,但我希望我的输出为
"abc":[{"1":"1","2":"2","3":"1","4":"2","5":"1","6":"2","7":"1","8":"2","9":"1","10":"2","11":"1"}]
帮我解决这个问题提前谢谢大家
解决方案
改变对象
jsonObject.put(order_product.getId(),""+order_product.getAns());
数据类型的变化
change the datatype of getAns() to in String in your POJO file
推荐阅读
- javascript - 使用 JSON 文件数据填充选择下拉列表
- bash - Kubernetes Helm bash 命令:bash: {"message":: command not found
- ruby-on-rails - 在 VS Code 中调试 Cucumber Ruby。错误:没有这样的文件或目录 - exec
- spring - 负载上基于 Spring Cloud Stream 内容的路由
- sql - 如何使用宏在 SAS 中获取当前月份名称和年份
- javascript - 递增/递减值函数 Localstorage
- node.js - Vue js 发布请求表单 | Vue.js 2
- javascript - JavaScript toISOString() 设置用户输入日期前一天的日期?
- arrays - 使用指针数学通过指针访问二维数组:需要数组类型 [Delphi]
- git - 如何从菜单中删除快捷方式?